home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Game Killer
/
Game_Killer.bin
/
291.QUEUE.INC
< prev
next >
Wrap
Text File
|
1991-07-08
|
1KB
|
48 lines
const
maxQueue = 600;
type
Queueitem = record dad, son : sector; end;
Queue = record
front, rear : 0..maxQueue;
data : array [1..maxQueue] of Queueitem;
end;
procedure serve( var q : queue; var e1, e2 : sector );
begin
if q.front = 0 then
writeln('serving from an empty queue!')
else
begin
e1 := q.data[ q.front ].dad;
e2 := q.data[ q.front ].son;
if q.front = maxQueue then
q.front := 1
else
q.front := q.front + 1;
if q.front = q.rear then { empty queue }
q.front := 0;
end; {else}
end; {serve}
procedure enqueue( var q : queue; e1, e2 : sector );
begin
if q.front = 0 then
begin
q.front := 1;
q.rear := 2;
q.data[1].dad:= e1;
q.data[1].son := e2;
end {if}
else if q.front = q.rear then
writeln('queue full!')
else
begin
q.data[ q.rear ].dad := e1;
q.data[ q.rear].son := e2;
if q.rear = maxQueue then
q.rear := 1
else
q.rear := q.rear + 1;
end; {else}
end; {enqueue}