program queue;
uses crt;
type
tipeinfo=integer;
tipeptr=^tipenode;
tipenode =record
info :tipeinfo;
next:tipeptr;
end;
tipequeue=tipeptr;
var stackpointer:tipequeue;
data: tipeinfo;
kata:string;
i:byte;
procedure inisialisasi(var queue:tipequeue);
begin
new(queue);
queue:=nil;
end;
function kosong(queue:tipequeue):boolean;
begin
kosong:=queue=nil;
end;
procedure enQueue(var queue:tipequeue; infobaru:tipeinfo);
var nodebaru:tipequeue;
begin
new(nodebaru);
nodebaru^.info:=infobaru;
nodebaru^.next:=queue;
queue:=nodebaru;
end;
function deQueue(var queue:tipequeue):integer;
var
temp,p:tipequeue;
begin
if not(kosong(queue)) then
begin
if(queue^.next = nil) then
begin
dequeue:=queue^.info;
queue:=nil;
end
else
begin
temp:=queue;
while(temp^.next^.next<>nil) do
begin
temp:=temp^.next;
end;
p:=temp^.next;
deQueue:=p^.info;
temp^.next:=nil;
dispose(p);
end;
end;
end;
procedure cetak(queue:tipequeue);
var temp:tipequeue;
begin
temp:=queue;
while (queue<>nil) do
begin
write(queue^.info,' ');
queue:=queue^.next;
end;
writeln;
end;
begin
inisialisasi(stackpointer);
enqueue(stackpointer,5);
//enqueue(stackpointer,2);
//enqueue(stackpointer,9);
cetak(stackpointer);
write('data yang di deQueue : ');
writeln(dequeue(stackpointer));
cetak(stackpointer);
readln;
end.
No comments:
Post a Comment