Queue/Definition: Difference between revisions
Content added Content deleted
(→Icon and Unicon: removed - moved to usage as push/pop are builtin) |
|||
Line 834: | Line 834: | ||
isEmpty _ = False |
isEmpty _ = False |
||
</lang> |
</lang> |
||
== Icon and Unicon == |
|||
==={{header|Icon}}=== |
|||
Icon and Unicon provide built-in queue and stack functions. |
|||
<lang Icon>procedure main(arglist) |
|||
queue := [] |
|||
write("Usage:\nqueue x x x - x - - - - -\n- pops elements\neverything else pushes") |
|||
write("Queue is:") |
|||
every x := !arglist do { |
|||
case x of { |
|||
"-" : pop(queue) | write("pop(empty) failed.) # pop if the next arglist[i] is a - |
|||
default : push(queue,x) # push arglist[i] |
|||
} |
|||
if empty(queue) then writes("empty") |
|||
else every writes(!queue," ") |
|||
write() |
|||
} |
|||
end |
|||
procedure empty(X) #: fail if X is not empty |
|||
if *X = 0 then return |
|||
end</lang> |
|||
==={{header|Unicon}}=== |
|||
This Icon solution works in Unicon. |
|||
=={{header|J}}== |
=={{header|J}}== |