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- Queueobjects are a type of- Enumerable- None - add item to the end of the queue - any type - returns the first element in the queue and removes it - any type - returns the first element in the queue without removing it - None - remove all elements - 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.