Queue/Usage: Difference between revisions
Content added Content deleted
Line 746: | Line 746: | ||
E also has queues in the standard library such as <code><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><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 |
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 := |
var queue := new Queue(); |
||
queue |
queue.push:1; |
||
queue |
queue.push:3; |
||
queue |
queue.push:5; |
||
// "Pop" items from the queue in FIFO order |
// "Pop" items from the queue in FIFO order |
||
console |
console.printLine(queue.pop()); // 1 |
||
console |
console.printLine(queue.pop()); // 3 |
||
console |
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 |
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 |
queue.pop() | on:(e){ console.writeLine:"Queue empty." } |
||
}</lang> |
|||
=={{header|Elisa}}== |
=={{header|Elisa}}== |