Queue
A queue is a data structure that manages elements in a first-in, first-out (FIFO) order.
Queues are commonly used in game development to manage events, actions, tasks, and other things that occur in a specific order. For example, queues can be used to manage the order of animation playback or the order of enemy actions in a game.
To create an empty queue and add elements to it:
typescript
let queue = new Queue<Number>();
for (let index = 0; index < 3; index++) {
queue.Enqueue(index);
}成员变量
Queue.items : T[] |
| All elements in the queue. |
Queue.count : number |
| The number of elements in the queue. |
成员方法
Queue.get ( index : number ) : T|undefined |
| Get the value of an element based on its index (index starts from 0). |
Queue.Enqueue ( item : T ) : void |
| Adds an element to the end of the queue. |
Queue.Dequeue ( ) : T|undefined |
| Removes an element from the front of the queue. |
Queue.Peek ( ) : T|undefined |
| Get the element at the front of the queue without removing it. |
Queue.Clear ( ) : void |
| Clears all elements from the queue. |
Queue.Swap ( rhs : Queue<T> ) : void |
| Swaps the elements in the current queue with the elements in the specified queue. |
Queue.toString ( ) : string |
| Returns the string representation of the current Queue object. |
Queue.forEach ( callback : Callback ) : void |
| Traverses the queue. |
