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
CollectionIsEmptyException
when stack is empty
Throws: pop(): T
Returns value from top of stack and removes it
CollectionIsEmptyException
when stack is empty
Throws: push(value: T): void
Add value to top of stack
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
CollectionIsFullException
when there is no space available
Throws: 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