Anonymous user
Queue/Usage: Difference between revisions
→{{header|Diego}}: Added Diego entry
m (→{{header|Phix}}: syntax coloured, added builtin version) |
(→{{header|Diego}}: Added Diego entry) |
||
Line 1,084:
queue.deja:28
queue.deja:10 in dequeue</pre>
=={{header|Diego}}==
Diego has a <code>queue</code> object and posit:
<lang diego>set_ns(rosettacode)_me();
add_queue({int},q)_values(1..4); // 1,2,3,4 (1 is first/bottom, 4 is last/top)
with_queue(q)_pop(); // 2,3,4
with_queue(q)_dequeue(); // 3,4
with_queue(q)_enqueue(5); // 3,4,5
with_queue(q)_push()_v(6,7); // 3,4,5,6,7
add_var({int},b)_value(8);
with_queue(q)_push[b]; // 3,4,5,6,7,8
with_queue(q)_pluck()_at(2); // callee will return `with_queue(q)_err(pluck invalid with queue);`
me_msg()_queue(q)_top(); // "8"
me_msg()_queue(q)_last(); // "8"
me_msg()_queue(q)_peek(); // "8"
me_msg()_queue(q)_bottom(); // "3"
me_msg()_queue(q)_first(); // "3"
me_msg()_queue(q)_peer(); // "3"
me_msg()_queue(q)_isempty(); // "false"
with_queue(q)_empty();
with_queue(q)_msg()_isempty()_me(); // "true" (alternative syntax)
with_queue()_pop(); // callee will return `with_queue(q)_err(pop invalid with empty queue);`
me_msg()_queue(q)_history()_all(); // returns the entire history of queue 'q' since its creation
reset_namespace[];</lang>
<code>queue</code> is a derivative of <code>array</code>, so arrays can also be used as queues.
=={{header|E}}==
|