Thursday, 6 January 2011
CONTOH PROGRAM STACK DALAM BAHASA PASCAL
Uses wincrt;
Const Elemen = 12;
Type S12 = String[Elemen];
stack = record
S : s12;
top : 0..elemen
end;
Var
A : stack;
I : Integer;
Kalimat : S12;
lanjut:boolean;
temp:char;
Procedure inisialisasi(Var A : stack);
Begin
A.top := 0
End;
function penuh(A:stack):boolean;
begin
penuh:=(A.top=elemen)
end;
function kosong(A:stack):boolean;
begin
kosong:=(A.top=0)
end;
function size(S:stack):integer;
begin
size:=s.top
end;
Procedure PUSH (Var A : stack; X : char);
Begin
A.top := A.top + 1;
A.S[A.top] := X
End;
Function POP (Var A : stack) : char;
Begin
POP := A.S[A.top];
A.top := A.top - 1;
End;
{Program Utama}
Begin
clrscr;
inisialisasi(A);
writeln('Menyusun sebuah kalimat dengan terbalik');
writeln('Masukan beberapa kalimat : ');
write('--- -_- --- --->:');
ReadLn (Kalimat);
writeln;
{ mempush kalimat ke dalam tumpukan}
For I := 1 to length(Kalimat) do
PUSH(A, Kalimat[I]);
{mempop isi tumpukan sehingga diperoleh kalimat yang dibaca terbalik}
For I := 1 to length(Kalimat) do
write(POP(A));
WriteLn;
end.
p
Subscribe to:
Post Comments (Atom)
wih anak unindra jugaa hahahah
ReplyDelete