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:
NameTypeRequiredDefaultDescription
capacitynumber-Number.MAX_VALUEMax 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:
NameTypeRequiredDefaultDescription
valueT+-
Throws: CollectionIsFullException when there is no space available



has(value: T): boolean

Check is stack has given value

Params:
NameTypeRequiredDefaultDescription
valueT+-



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