Queue/Usage: Difference between revisions

m
→‎{{header|REXX}}: changed spacing in the section header, added comments.
m (→‎{{header|REXX}}: removed STYLE from the PRE html tag.)
m (→‎{{header|REXX}}: changed spacing in the section header, added comments.)
Line 1,792:
The REXX language was developed under IBM VM/CMS operating system, and CMS had a stack mechanism built-into the
<br>operating system, so REXX utilized that resource.
 
<br>The '''queue''' instruction adds an entry to the bottom of the stack (FIFO),
<br>theThe &nbsp; '''pushqueue''' &nbsp; instruction adds an entry to the topbottom of the stack (LIFOFIFO).,
<br>Thethe &nbsp; '''queuedpush''' function&nbsp; returnsinstruction theadds numberan ofentry entriesto inthe top of the stack (LIFO).
 
<br>The '''pull''' or '''parse pull''' removes an entry from the top of the stack.
The &nbsp; '''queued''' &nbsp; function returns the number of entries in the stack.
<br>There are other instructions to manipulate the stack by "creating" mulitiple (named) stacks.
 
<br>The entries in the stack may be anything, including "nulls".
<br>The &nbsp; '''pull''' &nbsp; or &nbsp; '''parse pull''' &nbsp; removes an entry from the top of the stack.
<lang rexx>/*REXX program demonstrates three queue operations: push, pop, queued. */
 
say '══════════════════════════════════Pushing five values to the stack.'
<br>There are other instructions to manipulate the stack by "creating" mulitiplemultiple (named) stacks.
 
<br>The entries in the stack may be anything, including "nulls".
<lang rexx>/*REXX program demonstrates three queue operations: push, pop, queuedempty. */
say '══════════════════════════════════ Pushing five values to the stack.'
do j=1 for 4 /*loop to PUSH four values. */
call push j*10 /*PUSH (aka enqueue to stack). */
say 'pushed value:' j*10 /*echo the pushed value. */
if j\==3 then iterate /*also, insert a "null" entry. */
call push /*PUSH (aka enqueue to stack). */
say 'pushed a "null" value.' /*echo what was pushed. */
end /*j*/
say '══════════════════════════════════Popping══════════════════════════════════ Popping all values from the stack.'
do m=1 while \empty() /*EMPTY (returns TRUE if empty). */
call pop /*POP (aka dequeue from stack).*/
say m': popped value=' result /*echo the popped value. */
end /*m*/
say '══════════════════════════════════ The stack is now empty.'
say '══════════════════════════════════The stack is now empty.'
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────subroutines/functions/operators. */
Line 1,820 ⟶ 1,825:
'''output'''
<pre>
══════════════════════════════════ Pushing five values to the stack.
══════════════════════════════════Pushing five values to the stack.
pushed value: 10
pushed value: 20
Line 1,826 ⟶ 1,831:
pushed a "null" value.
pushed value: 40
══════════════════════════════════ Popping all values from the stack.
══════════════════════════════════Popping all values from the stack.
1: popped value= 10
2: popped value= 20
Line 1,832 ⟶ 1,837:
4: popped value=
5: popped value= 40
══════════════════════════════════ The stack is now empty.
══════════════════════════════════The stack is now empty.
</pre>