Jump to content

Queue/Usage: Difference between revisions

m
Line 746:
E also has queues in the standard library such as <code>&lt;import:org.erights.e.examples.concurrency.makeQueue></code>, but they are designed for concurrency purposes and do not report emptiness but rather return a promise for the next element.
=={{header|Elena}}==
ELENA 3.4.x :
<lang elena>import system'collections.;
import extensions.;
public program()
{
[
console.
// Create a queue and "push" items into it
var queue := Queue new. Queue();
queue .push:1.;
queue .push:3.;
queue .push:5.;
// "Pop" items from the queue in FIFO order
console .printLine(queue .pop().); // 1
console .printLine(queue .pop().); // 3
console .printLine(queue .pop().); // 5
// To tell if the queue is empty, we check the count
console .printLine("queue is ",(queue length.Length == 0) .iif("empty","nonempty")).;
// If we try to pop from an empty queue, an exception
// is thrown.
queue .pop() | if(on:(e)[{ console .writeLine:"Queue empty.". ].}
]}</lang>
 
=={{header|Elisa}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.