Queue/Definition: Difference between revisions

Content added Content deleted
(+Icon+Unicon)
Line 837: Line 837:
== Icon and Unicon ==
== Icon and Unicon ==
==={{header|Icon}}===
==={{header|Icon}}===
Icon and Unicon provide built-in queue and stack functions.
<lang Icon>procedure main(arglist)
<lang Icon>procedure main(arglist)
queue := []
queue := []
Line 843: Line 844:
every x := !arglist do {
every x := !arglist do {
case x of {
case x of {
"-" : pop(queue) # pop if the next arglist[i] is a -
"-" : pop(queue) | write("pop(empty) failed.) # pop if the next arglist[i] is a -
default : push(queue,x) # push arglist[i]
default : push(queue,x) # push arglist[i]
}
}
if empty(queue) then stop("empty")
if empty(queue) then writes("empty")
else every writes(!queue," ")
else every writes(!queue," ")
write()
write()
Line 855: Line 856:
if *X = 0 then return
if *X = 0 then return
end</lang>
end</lang>

==={{header|Unicon}}===
==={{header|Unicon}}===
This Icon solution works in Unicon.
This Icon solution works in Unicon.