program antrian
Uses winCrt;
Type
Point = ^Rec;
Rec = record
isi : char;
next: Point;
end;
queue = record
Head : Point;
Tail : Point;
end;
var
Q : queue;
i,k : byte; { i = tinggi_stack }
Procedure GambarPipa;
Var y : byte;
begin
GotoXY(39,8);write('\ /');
For y:=1 to 10 do
begin
GotoXY(40,y+8);write('³');
GotoXY(46,y+8);write('³');
end;
GotoXY(40,19);write('À³ ³Ù');
GotoXY(61,21);write('\');
GotoXY(61,23);write('/');
end;
Function Empty: boolean;
begin
if Q.Head = nil then
Empty:= True else
Empty:= False;
end;
Function Full: boolean;
begin
if i = 10 then
Full:= True else
Full:= False;
end;
Procedure Enqueue;
VAR Now : Point;
begin
if Full then
begin
GotoXY(1,6);write('queue sudah penuh ....');
GotoXY(1,6);ClrEol;
end else
begin
New(Now);
GotoXY(1,7);ClrEol; write('Masukkan satu huruf = ');
Now^.isi:=ReadKey; write(Now^.isi);
Now^.next := nil;
For k:=1 to 20 do
begin
GotoXY(k+22,7);write(' ');
GotoXY(k+23,7);write(Now^.isi);
end;
For k:= 1 to 11-i do
begin
GotoXY(43,k+6);write(' ');
GotoXY(43,k+7);write(Now^.isi);
end;
Inc(i);
GotoXY(1,7);ClrEol;
if Empty then
begin
Q.Head := Now;
Q.Tail := Now;
end else
begin
Q.Tail^.next := Now;
Q.Tail := Now;
end;
end;
end;
Procedure Dequeue;
Var u : byte;
Now : Point;
begin
if Empty then
begin
GotoXY(1,6);write('queue Kosong ....');
GotoXY(1,6);ClrEol;
end else
begin
For k:=19 to 22 do
begin
GotoXY(43,k-1);write(' ');
GotoXY(43,k);write(Q.Head^.isi);
end;
For k:= 43 to 63 do
begin
GotoXY(k,22);write(' ');
GotoXY(k+1,22);write(Q.Head^.isi);
end;
Now:= Q.Head;
Q.Head:= Q.Head^.next;
Dispose(Now);
Dec(i);
Now:= Q.Head;
K:=18;
While Now <> nil do
begin
GotoXY(43,k);write(Now^.isi);
Now:= Now^.next;
Dec(K);
end;
GotoXY(43,K);write(' ');
end;
end;
Procedure Create;
begin
Q.Head := nil;
Q.Tail := nil;
end;
Procedure Clear;
begin
While not Empty do Dequeue;
end;
Procedure Menu;
Var jwb : char;
begin
i := 0;
GotoXY(1,2);write('1. Enqueue ');
GotoXY(1,3);write('2. Dequeue ');
GotoXY(1,4);write('3. Quit');
Create;
Repeat
GotoXY(1,5);ClrEol; write('Pilihan [1/2/3] = ');
jwb:=ReadKey; write(jwb);
Case jwb of
'1' : Enqueue;
'2' : Dequeue;
end;
Until jwb = '3';
Clear;
end;
{Main Program}
Begin
ClrScr;
GambarPipa;
Menu;
End.
Komentar