Reference

Queue

New

Input A list of elements.
Output A queue containing the list of elements with the first element at the beginning of the queue.

Signature

queue_new(a: List): Queue

Example

queue_new([1, 2, 3]) // returns a queue with 1 at the front

Enqueue

Input A queue and an element.
Output A new queue with the element added to the end.

Signature

queue_enqueue(a: Queue, b: Any): Queue

Example

queue_enqueue(queue_new([1, 2]), 3) // returns a queue [1, 2, 3]

Dequeue

Input A queue.
Output A new queue with the element at the beginning removed.

Signature

queue_dequeue(a: Queue): Queue

Example

queue_dequeue(queue_new([1, 2, 3])) // returns a queue [2, 3]

Peek

Input A queue.
Output The element at the beginning of the queue.

Signature

queue_peek(a: Queue): Any

Example

queue_peek(queue_new([1, 2, 3])) // returns 1

Reverse

Input A queue.
Output A new queue with the elements in reverse order.

Signature

queue_reverse(a: Queue): Queue

Example

queue_reverse(queue_new([1, 2, 3])) // returns a queue [3, 2, 1]

Is Empty

Input A queue.
Output True if the queue is empty, false otherwise.

Signature

queue_isEmpty(a: Queue): Boolean

Example

queue_isEmpty(queue_new([])) // returns true

Is Not Empty

Input A queue.
Output True if the queue is not empty, false otherwise.

Signature

queue_isNotEmpty(a: Queue): Boolean

Example

queue_isNotEmpty(queue_new([1, 2])) // returns true

Length

Input A queue.
Output The number of elements in the queue.

Signature

queue_length(a: Queue): Number

Example

queue_length(queue_new([1, 2, 3])) // returns 3