tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
34
Task/Queue-Definition/Oz/queue-definition.oz
Normal file
34
Task/Queue-Definition/Oz/queue-definition.oz
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
declare
|
||||
fun {NewQueue}
|
||||
Stream
|
||||
WritePort = {Port.new Stream}
|
||||
ReadPos = {NewCell Stream}
|
||||
in
|
||||
WritePort#ReadPos
|
||||
end
|
||||
|
||||
proc {Push WritePort#_ Value}
|
||||
{Port.send WritePort Value}
|
||||
end
|
||||
|
||||
fun {Empty _#ReadPos}
|
||||
%% the queue is empty if the value at the current
|
||||
%% read position is not determined
|
||||
{Not {IsDet @ReadPos}}
|
||||
end
|
||||
|
||||
fun {Pop _#ReadPos}
|
||||
%% blocks if empty
|
||||
case @ReadPos of X|Xr then
|
||||
ReadPos := Xr
|
||||
X
|
||||
end
|
||||
end
|
||||
|
||||
Q = {NewQueue}
|
||||
in
|
||||
{Show {Empty Q}}
|
||||
{Push Q 42}
|
||||
{Show {Empty Q}}
|
||||
{Show {Pop Q}}
|
||||
{Show {Empty Q}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue