Queue

A Queue is a collection of any type in kOS. Queues work according to First-In first-out principle. It may be useful to contrast Queue with Stack to better understand how both structures work. You can read more about queues on Wikipedia.

Using a queue

SET Q TO QUEUE().
Q:PUSH("alice").
Q:PUSH("bob").

PRINT Q:POP. // will print 'alice'
PRINT Q:POP. // will print 'bob'

Structure

structure Queue
Members
Suffix Type Description
All suffixes of Enumerable   Queue objects are a type of Enumerable
PUSH(item) None add item to the end of the queue
POP() any type returns the first element in the queue and removes it
PEEK() any type returns the first element in the queue without removing it
CLEAR() None remove all elements
COPY Queue a new copy of this queue

Note

This type is serializable.

Queue:PUSH(item)
Parameters:
  • item – (any type) item to be added

Adds the item to the end of the queue.

Queue:POP()

Returns the item in the front of the queue and removes it.

Queue:PEEK()

Returns the item in the front of the queue without removing it.

Queue:CLEAR()

Removes all elements from the queue.

Queue:COPY
Type:Queue
Access:Get only

Returns a new queue that contains the same thing as the old one.