{Program Stack
made Agung raharja
tgl.26 Nop 2009}
program tumpukan;
uses
wincrt;
type
PStackType =^StackType;
StackType = record
data : Integer;
Next : PStackType;
end;
var
stack:PStackType;
input : string;
data, code,i :integer;
procedure Push(Var s:PStackType; d:integer);
var
r : PStackType;
begin
new(r);
r^.Data := d;
r^.next := s;
s :=r;
end;
function Pop(var s:PStackType):Integer;
var
r:PStackType;
begin
pop :=0;
if (s <> nil) then
begin
r :=s;
s :=s^.Next;
Pop := r^.Data;
Dispose(r);
end;
end;
procedure TampilStack(s:PStackType);
begin
if (s <> nil) then
begin
write(s^.Data:5);
TampilStack(s^.Next);
end;
end;
begin
writeln('Procedure Stack');
writeln('===============');
writeln;
Stack := nil;
repeat
write('Masukkan angka');
readln(input);
if (input <> '') then
begin
Val(Input, Data, Code);
if (code <> 0) then
data :=0;
Push(Stack, data);
end;
until (input ='');
writeln;
writeln('Di Dalam Stack');
TampilStack(Stack);
writeln;
writeln;
writeln('Memproses Stack:');
i:=1;
while (stack <> nil) do
begin
writeln('Tumpukan ke-', i, ':', Pop(Stack));
inc(i);
end;
end.
0 komentar:
Posting Komentar