uses crt;
const
elemen =255; {batas maximum karakter}
type
S255 = string [elemen];
tumpukan = record
isi : s255;
atas : 0..elemen;
end;
var
T : tumpukan;
W : char;
kalimat : s255;
i,j : integer;
procedure awalan (var T : tumpukan);
begin
T.Atas := 0;
end;
procedure push (var T : tumpukan; X : char);
begin
T. Atas := T.Atas+1;
T.Isi[T.Atas] := X;
end;
function pop (var T : tumpukan): char;
begin
pop := T.Isi[T.Atas];
T.atas := T.atas-1;
end;
begin {program utama}
clrscr; {melakukan proses push}
writeln('Masukkan Kalimat : ');
read(kalimat);
writeln;
for i := 1 to length (kalimat) do
push (T, kalimat [i]);
write('Elemen yang di-push : ', kalimat);
writeln;
readln;
{melakukan proses pop}
for i := 1 to length (kalimat) do
push (t, kalimat [i]);
writeln;
writeln('Hasil akhir push dibaca dengan pop : ');
{menampilkan hasil proses pop}
for j := 1 to length (kalimat) do
begin
w := pop (T);
write(w);
end;
readln;
end.
No comments:
Write komentar