RosettaCodeData/Task/Queue-Usage/REXX/queue-usage.rexx

23 lines
2.1 KiB
Rexx
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
/*REXX program demonstrates four queueing operations: push, pop, empty, query. */
2015-02-20 00:35:01 -05:00
say ' Pushing five values to the stack.'
2019-09-12 10:33:56 -07:00
do j=1 for 4 /*a DO loop to PUSH four values. */
call push j * 10 /*PUSH (aka: enqueue to the stack).*/
say 'pushed value:' j * 10 /*echo the pushed value. */
if j\==3 then iterate /*Not equal 3? Then use a new number.*/
call push /*PUSH (aka: enqueue to the stack).*/
say 'pushed a "null" value.' /*echo what was pushed to the stack. */
2013-04-10 23:57:08 -07:00
end /*j*/
2019-09-12 10:33:56 -07:00
say ' Quering the stack (number of entries).'
say queued() ' entries in the stack.'
2015-02-20 00:35:01 -05:00
say ' Popping all values from the stack.'
2019-09-12 10:33:56 -07:00
do k=1 while \empty() /*EMPTY (returns TRUE [1] if empty).*/
call pop /*POP (aka: dequeue from the stack).*/
say k': popped value=' result /*echo the popped value. */
end /*k*/
2015-02-20 00:35:01 -05:00
say ' The stack is now empty.'
2019-09-12 10:33:56 -07:00
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
push: queue arg(1); return /*(The REXX QUEUE is FIFO.) */
pop: procedure; parse pull x; return x /*REXX PULL removes a stack item. */
empty: return queued()==0 /*returns the status of the stack. */