tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
28
Task/Queue-Definition/PL-I/queue-definition.pli
Normal file
28
Task/Queue-Definition/PL-I/queue-definition.pli
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* To push a node onto the end of the queue. */
|
||||
push: procedure (tail);
|
||||
declare tail handle (node), t handle (node);
|
||||
t = new(:node:);
|
||||
get (t => value);
|
||||
if tail ^= bind(:null, node:) then
|
||||
tail => link = t;
|
||||
/* If the queue was non-empty, points the tail of the queue */
|
||||
/* to the new node. */
|
||||
tail = t; /* Point "tail" at the end of the queue. */
|
||||
tail => link = bind(:node, null:);
|
||||
end push;
|
||||
|
||||
/* To pop a node from the head of the queue. */
|
||||
pop: procedure (head, val);
|
||||
declare head handle (node), val fixed binary;
|
||||
if head = bind(:node, null:) then signal error;
|
||||
val = head => value;
|
||||
head = head => pointer; /* pops the top node. */
|
||||
if head = bind(:node, null:) then tail = head;
|
||||
/* (If the queue is now empty, make tail null also.) */
|
||||
end pop;
|
||||
|
||||
/* Queue status: the EMPTY function, returns true for empty queue. */
|
||||
empty: procedure (h) returns (bit(1));
|
||||
declare h handle (Node);
|
||||
return (h = bind(:Node, null:) );
|
||||
end empty;
|
||||
Loading…
Add table
Add a link
Reference in a new issue