program tumpukkan;
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('program 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('didalam stack :');
tampilstack(stack);
writeln;
writeln;
writeln('memproses stack');
i:=1;
while(stack<>nil) do
begin
writeln('tumpukkan ke-' ,i, ': ',pop(stack));
inc(i);
end;
end.
[Pascal ] Pointer dan stack
Reviewed by
I Made Purwantara
on
14.30
Rating:
5
Tidak ada komentar: