End Program StackdglinkedList;
uses wincrt;
type
PLinkedList = ^TlinkedList;
TLinkedlist = record
info : integer;
next : PlinkedList;
end;
Procedure Push(Var s:Plinkedlist; x:integer);
var q : Plinkedlist;
Begin
new(q);q^.info:=x;q^.next:=s;s:=q;
End;
function Pop(Var s :PlinkedList):integer;
var t : PlinkedList;
Begin
if (s<>nil) then begin
t:=s; pop:=s^.info; s:=s^.next;dispose(t);
end;
End;
Procedure Display(s:PlinkedList);
Begin
while s<> nil do begin
write(s^.info:5); s:=s^.next;
end;
writeln;
End;
{Program utama}
var a :Plinkedlist; y:integer;
Begin
A:= nil;
push(A,7);Push(A,6);Push(A,1);
Display(A);
REadln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
End.
Output : 1 6 7
Hasil pop : 1
Hasil pop : 6
Hasil pop : 7
3.Program stack
Program StackdglinkedList;
uses wincrt;
type
PLinkedList = ^TlinkedList;
TLinkedlist = record
info : integer;
next : PlinkedList;
end;
{menambah elemen baru pada stack}
Procedure Push(Var s:Plinkedlist; x:integer);
var q : Plinkedlist;
Begin
new(q);
q^.info:=x;
q^.next:=s;
s:=q;
End;
function Pop(Var s :PlinkedList):integer;
var t : PlinkedList;
Begin
if (s<>nil) then begin
t:=s; pop:=s^.info; s:=s^.next;dispose(t);
end;
End;
Procedure Display(s:PlinkedList);
Begin
while s<> nil do begin
write(s^.info:5); s:=s^.next;
end;
writeln;
End;
{Program utama}
var a :Plinkedlist; y:integer;
Begin
A:= nil;
push(A,2);Push(A,1);Push(A,7);Push(A,9);
Display(A);
REadln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
Output : 9 7 1 2
Hasil pop : 9
Hasil pop : 7
Hasil pop : 1
Hasil pop : 2
uses wincrt;
type
PLinkedList = ^TlinkedList;
TLinkedlist = record
info : integer;
next : PlinkedList;
end;
Procedure Push(Var s:Plinkedlist; x:integer);
var q : Plinkedlist;
Begin
new(q);q^.info:=x;q^.next:=s;s:=q;
End;
function Pop(Var s :PlinkedList):integer;
var t : PlinkedList;
Begin
if (s<>nil) then begin
t:=s; pop:=s^.info; s:=s^.next;dispose(t);
end;
End;
Procedure Display(s:PlinkedList);
Begin
while s<> nil do begin
write(s^.info:5); s:=s^.next;
end;
writeln;
End;
{Program utama}
var a :Plinkedlist; y:integer;
Begin
A:= nil;
push(A,7);Push(A,6);Push(A,1);
Display(A);
REadln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
End.
Output : 1 6 7
Hasil pop : 1
Hasil pop : 6
Hasil pop : 7
3.Program stack
Program StackdglinkedList;
uses wincrt;
type
PLinkedList = ^TlinkedList;
TLinkedlist = record
info : integer;
next : PlinkedList;
end;
{menambah elemen baru pada stack}
Procedure Push(Var s:Plinkedlist; x:integer);
var q : Plinkedlist;
Begin
new(q);
q^.info:=x;
q^.next:=s;
s:=q;
End;
function Pop(Var s :PlinkedList):integer;
var t : PlinkedList;
Begin
if (s<>nil) then begin
t:=s; pop:=s^.info; s:=s^.next;dispose(t);
end;
End;
Procedure Display(s:PlinkedList);
Begin
while s<> nil do begin
write(s^.info:5); s:=s^.next;
end;
writeln;
End;
{Program utama}
var a :Plinkedlist; y:integer;
Begin
A:= nil;
push(A,2);Push(A,1);Push(A,7);Push(A,9);
Display(A);
REadln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
y:=Pop(A);
writeln('Hasil pop:',y);
readln;
Output : 9 7 1 2
Hasil pop : 9
Hasil pop : 7
Hasil pop : 1
Hasil pop : 2
Tidak ada komentar:
Posting Komentar