RosettaCodeData/Task/Queue-Usage/Elena/queue-usage.elena

25 lines
654 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
import system'collections;
import extensions;
2026-02-01 16:33:20 -08:00
public Program()
2023-07-01 11:58:00 -04:00
{
// Create a queue and "push" items into it
var queue := new Queue();
2024-03-06 22:25:12 -08:00
queue.push(1);
queue.push(3);
queue.push(5);
2023-07-01 11:58:00 -04:00
// "Pop" items from the queue in FIFO order
2026-02-01 16:33:20 -08:00
Console.printLine(queue.pop()); // 1
Console.printLine(queue.pop()); // 3
Console.printLine(queue.pop()); // 5
2023-07-01 11:58:00 -04:00
// To tell if the queue is empty, we check the count
2026-02-01 16:33:20 -08:00
Console.printLine("queue is ",(queue.Length == 0).iif("empty","nonempty"));
2023-07-01 11:58:00 -04:00
// If we try to pop from an empty queue, an exception
// is thrown.
2026-02-01 16:33:20 -08:00
queue.pop() \\ on::(e){ Console.writeLine("Queue empty.") }
2023-07-01 11:58:00 -04:00
}