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