Queue/Usage: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments, statements, and whitespace, used a template for the output section.)
Line 2,257: Line 2,257:


The entries in the stack may be anything, including "nulls".
The entries in the stack may be anything, including "nulls".
<lang rexx>/*REXX program demonstrates three queue operations: push, pop, empty. */
<lang rexx>/*REXX program demonstrates four queueing operations: push, pop, empty, query. */
say '══════════════════════════════════ Pushing five values to the stack.'
say '══════════════════════════════════ Pushing five values to the stack.'
do j=1 for 4 /*loop to PUSH four values. */
do j=1 for 4 /*a DO loop to PUSH four values. */
call push j*10 /*PUSH (aka enqueue to stack). */
call push j * 10 /*PUSH (aka: enqueue to the stack).*/
say 'pushed value:' j*10 /*echo the pushed value. */
say 'pushed value:' j * 10 /*echo the pushed value. */
if j\==3 then iterate /*also, insert a "null" entry. */
if j\==3 then iterate /*Not equal 3? Then use a new number.*/
call push /*PUSH (aka enqueue to stack). */
call push /*PUSH (aka: enqueue to the stack).*/
say 'pushed a "null" value.' /*echo what was pushed. */
say 'pushed a "null" value.' /*echo what was pushed to the stack. */
end /*j*/
end /*j*/
say '══════════════════════════════════ Quering the stack (number of entries).'
say queued() ' entries in the stack.'
say '══════════════════════════════════ Popping all values from the stack.'
say '══════════════════════════════════ Popping all values from the stack.'
do m=1 while \empty() /*EMPTY (returns TRUE if empty). */
do k=1 while \empty() /*EMPTY (returns TRUE [1] if empty).*/
call pop /*POP (aka dequeue from stack).*/
call pop /*POP (aka: dequeue from the stack).*/
say m': popped value=' result /*echo the popped value. */
say k': popped value=' result /*echo the popped value. */
end /*m*/
end /*k*/
say '══════════════════════════════════ The stack is now empty.'
say '══════════════════════════════════ The stack is now empty.'
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────subroutines/functions/operators. */
push: queue arg(1); return /*REXX QUEUE is FIFO. */
push: queue arg(1); return /*(The REXX QUEUE is FIFO.) */
pop: procedure; pull x; return x /*REXX PULL removes a stack item*/
pop: procedure; parse pull x; return x /*REXX PULL removes a stack item. */
empty: return queued()==0 /*returns the status of the stack*/</lang>
empty: return queued()==0 /*returns the status of the stack. */</lang>
'''output'''
{{out|output|text=:}}
<pre>
<pre>
══════════════════════════════════ Pushing five values to the stack.
══════════════════════════════════ Pushing five values to the stack.
Line 2,285: Line 2,287:
pushed a "null" value.
pushed a "null" value.
pushed value: 40
pushed value: 40
══════════════════════════════════ Quering the stack (number of entries).
5 entries in the stack.
══════════════════════════════════ Popping all values from the stack.
══════════════════════════════════ Popping all values from the stack.
1: popped value= 10
1: popped value= 10