Queue<T>
Guide: /guide/data-structures/queue
Generic Types
T
- type of collection elements
Implements interfaces
ILinearStorage
Methods
constructor(capacity?: number): Queue<T>
Creates empty instance
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
capacity | number | - | Number.MAX_VALUE | Max capacity of queue (> 0) |
peek(): T
Returns value from top of queue
CollectionIsEmptyException
when queue is empty
Throws: pop(): T
Returns value from top of queue and removes it
CollectionIsEmptyException
when queue is empty
Throws: push(value: T): void
Add value to top of queue
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
CollectionIsFullException
when there is no space available
Throws: has(value: T): boolean
Check is queue has given value
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
clear(): void
Remove all elements from queue
isEmpty(): boolean
Check is queue has any value, returns true if queue is empty
isFull(): boolean
Check is queue length exceed max capacity
length(): number
Get queue size