Queue/Usage: Difference between revisions

2,861 bytes added ,  12 years ago
→‎{{header|REXX}}: added the REXX language. -- ~~~~
(added standard ml)
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
Line 1,309:
Queue is empty.
Trying to pop an empty queue yields: none</pre>
 
=={{header|REXX}}==
===version 1===
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 tapped into that resource.
<br>The <tt> queue </tt> instruction adds an entry to the bottom of the stack,
<br>the <tt> push </tt> instruction adds an entry to the top of the stack.
<br>The <tt> queued() </tt> 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><br>This REXX version mainly uses the <tt> PUSH </tt> instruction.
<lang rexx>/*REXX program demonstrates queue data structure. */
 
queue 'This is the first entry being put into da queue.'
 
do j=1 to 20 by 2
queue j /*add this to the bottom of queue*/
if j==11 then queue /*add a "null" entry to the queue*/
end
 
push 'hot-shot!' /*put this on the top of queue. */
queue 'This is the last entry being put into the queue.'
 
do k=1 while queued()\==0
parse pull n /*pull from the top of the queue.*/
say right(k,3) 'entry is ===>' n
end</lang>
Output:
<pre style="height:45ex;overflow:scroll">
1 entry is ===> hot-shot!
2 entry is ===> This is the first entry being put into da queue.
3 entry is ===> 1
4 entry is ===> 3
5 entry is ===> 5
6 entry is ===> 7
7 entry is ===> 9
8 entry is ===> 11
9 entry is ===>
10 entry is ===> 13
11 entry is ===> 15
12 entry is ===> 17
13 entry is ===> 19
14 entry is ===> This is the last entry being put into the queue.
</pre>
===version 2===
This REXX version mainly uses the <tt> PUSH </tt> instruction.
<lang rexx>/*REXX program demonstrates queue data structure. */
 
push 'This is the first entry being put into da queue.'
 
do j=10 to 200 by 20
push j /*add this to the top of queue. */
if j==90 then push /*add a "null" entry to the queue*/
end
 
queue 'low-ball' /*push this on the top of queue.*/
push 'This is the last entry being put into the queue.'
 
do k=1
if queued()==0 then leave
parse pull n /*pull from the top of the queue.*/
say right(k,3) 'entry is ===>' n
end</lang>
Output:
<pre style="height:45ex;overflow:scroll">
1 entry is ===> This is the last entry being put into the queue.
2 entry is ===> 190
3 entry is ===> 170
4 entry is ===> 150
5 entry is ===> 130
6 entry is ===> 110
7 entry is ===>
8 entry is ===> 90
9 entry is ===> 70
10 entry is ===> 50
11 entry is ===> 30
12 entry is ===> 10
13 entry is ===> This is the first entry being put into da queue.
14 entry is ===> low-ball
</pre>
 
=={{header|Ruby}}==