Queue/Usage: Difference between revisions

Content added Content deleted
Line 746: 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.
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}}==
=={{header|Elena}}==
ELENA 3.4 :
ELENA 4.x :
<lang elena>import system'collections.
<lang elena>import system'collections;
import extensions.
import extensions;
public program
public program()
{
[
console.
// Create a queue and "push" items into it
// Create a queue and "push" items into it
var queue := Queue new.
var queue := new Queue();
queue push:1.
queue.push:1;
queue push:3.
queue.push:3;
queue push:5.
queue.push:5;
// "Pop" items from the queue in FIFO order
// "Pop" items from the queue in FIFO order
console printLine(queue pop). // 1
console.printLine(queue.pop()); // 1
console printLine(queue pop). // 3
console.printLine(queue.pop()); // 3
console printLine(queue pop). // 5
console.printLine(queue.pop()); // 5
// To tell if the queue is empty, we check the count
// To tell if the queue is empty, we check the count
console printLine("queue is ",(queue length == 0) iif("empty","nonempty")).
console.printLine("queue is ",(queue.Length == 0).iif("empty","nonempty"));
// If we try to pop from an empty queue, an exception
// If we try to pop from an empty queue, an exception
// is thrown.
// is thrown.
queue pop | if(:e)[ console writeLine:"Queue empty.". ].
queue.pop() | on:(e){ console.writeLine:"Queue empty." }
]</lang>
}</lang>


=={{header|Elisa}}==
=={{header|Elisa}}==