Jump to content

Queue/Definition: Difference between revisions

Added "when isMainModule". Moved "try" before the first "pop".
(Removed "import queues" as module no longer exists. Added description of queue and basic operations. Added try..except when popping from empty queue.)
(Added "when isMainModule". Moved "try" before the first "pop".)
Line 3,659:
if queue.isEmpty: queue.tail = nil
 
var fifo = initQueue[int]()
 
when isMainModule:
fifo.push(26)
 
fifo.push(99)
var fifo = initQueue[int]()
fifo.push(2)
 
echo "Fifo size: ", fifo.len()
echo "Popping: ", fifo.poppush(26)
echo "Popping: ", fifo.poppush(99)
echo "Popping: ", fifo.poppush(2)
echo "Fifo size: ", fifo.len()
try:
echo "Popping: ", fifo.pop()
except ValueError:
echo "Exception catchedPopping: ", getCurrentExceptionMsgfifo.pop()</lang>
echo "Popping: ", fifo.pop()
echo "Popping: ", fifo.pop()
except ValueError:
echo "Exception catched: ", getCurrentExceptionMsg()</lang>
{{out}}
<pre>Fifo size: 3
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.