Friday, July 23, 2010

queue dengan array di pascal

program queue;
uses crt;

const max=100;

type
  tipeinfo=integer;
//  tipeptr=^tipenode;
  tipequeue =record
    info :array [1..max] of integer;
    belakang:integer;
  end;
//  tipequeue=tipeptr;

var stackpointer:tipequeue;
    data: tipeinfo;
    kata:string;
    i:byte;

procedure inisialisasi(var myqueue:tipequeue);
begin
//  new(myqueue);
  myqueue.belakang:=0;
end;


function kosong(var myqueue:tipequeue):boolean;
begin
         kosong:=myqueue.belakang=0;
end;


function penuh(var myqueue:tipequeue):boolean;
begin
         penuh:=myqueue.belakang=max;
end;


procedure enQueue(var myqueue:tipequeue; infobaru:integer);

begin
if not(penuh(myqueue)) then begin
inc(myqueue.belakang);
myqueue.info[myqueue.belakang]:=infobaru;          end;
end;


function deQueue(var myqueue:tipequeue):integer;
var i:integer;
begin
if not(kosong(myQueue)) then
   begin
        deQueue:=myqueue.info[1];
        for i:=1 to myqueue.belakang-1 do
           myqueue.info[i]:=myqueue.info[i+1];
   end;
end;


procedure cetak(myqueue:tipequeue);
var i:integer;
begin
if not(kosong(myqueue)) then begin
for i:=1 to myqueue.belakang do
 write(myqueue.info[i],' ');
writeln;
writeln;
end else writeln('kosong');
end;

begin
inisialisasi(stackpointer);
cetak(stackpointer);
enqueue(stackpointer,5);
enqueue(stackpointer,2);
enqueue(stackpointer,9);
cetak(stackpointer);
writeln(deQueue(stackpointer));
readln;

end.

No comments: