Difference between revisions of "ObjectType:queue"
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
== Methods == | == Methods == | ||
− | *Clear: Removes all objects in the queue | + | *'''Clear''': Removes all objects in the queue |
− | *Queue[...]: Adds an object to the queue, passing any parameters to the initialization for the given object type | + | *'''Queue['''...''']''': Adds an object to the queue, passing any parameters to the initialization for the given object type |
− | *Dequeue: Removes the first object in the queue | + | *'''Dequeue''': Removes the first object in the queue |
− | *GetIterator[iterator object]: Initializes an iterator object for use with this queue | + | *'''GetIterator['''iterator object''']''': Initializes an iterator object for use with this queue |
== Declaring queue Variables == | == Declaring queue Variables == |
Revision as of 15:41, 3 May 2006
Contents
Overview
queue | |
Defined By | LavishScript |
Inherits | none |
Reduces To | NULL |
Variable Object Type | queue |
Uses Sub-Types | yes |
C/C++ Type | LSQueue * |
A queue is a first-in first-out (as if waiting in a line) list of objects.
Members
- int Size: Number of objects in the queue
- sub-type Peek: Retrieves the first object in the queue (first in line)
Methods
- Clear: Removes all objects in the queue
- Queue[...]: Adds an object to the queue, passing any parameters to the initialization for the given object type
- Dequeue: Removes the first object in the queue
- GetIterator[iterator object]: Initializes an iterator object for use with this queue
Declaring queue Variables
Queue objects require a sub-type -- an object type to be a queue of. Append the sub-type to the word queue, with a colon separating the words. It is possible to have sub-subtypes (such as queue:queue:int for a queue of queues of ints).
Example 1
Declaring a queue of "int"
variable queue:int MyQueue
Adding items to a queue
To add an item to a queue, use the Queue method, as demonstrated in this example
Example 1
variable queue:int MyQueue MyQueue:Queue[15] MyQueue:Queue[25]
Removing items from a queue
Items are removed in the order queued -- the first item queued is the first that will be removed. To remove an item, use the Dequeue method, as demonstrated in this example
Example 1
variable queue:int MyQueue MyQueue:Queue[15] MyQueue:Queue[25] MyQueue:Dequeue /* Only 25 is now in the queue */
Viewing the queue
To access the first object in the queue (e.g. the first person in line), use the Peek member, as demonstrated in this example
Example 1
variable queue:int MyQueue MyQueue:Queue[15] MyQueue:Queue[25] echo \${MyQueue.Peek} should be 15: =${MyQueue.Peek} MyQueue:Dequeue /* Only 25 is now in the queue */ echo \${MyQueue.Peek} should be 25: =${MyQueue.Peek}