An array based stack implementation. Allocation of memory for the stack is lazy during the first call to modifying methods. If necessary, you can replace the internal implementation with a more suitable one for your tasks.
- T - stack element type
Constructor(deep: number): Stack<T>
Creates a stack instance at the specified depth.
The default implementation creates an array of length
ArgumentNullError - an exception thrown if you do not pass the
StackDepthNegativeError - an exception thrown if value of the
deepparameter is less than zero.
Note. If you pass
+Infinityas the parameter value, then an array will be created with no explicit length limit.
push (item: T): void
Add item to the top of the stack.
- StackOverflowError - an exception thrown when trying to add an item to the full stack.
pop (): T
Remove item from the top of the stack and return it.
- StackUnderflowError - an exception thrown when an attempt to pop an element from empty stack.
clear (): void
Clear all elements from the stack.
- StackUnderflowError - an exception thrown when trying to clear an empty stack.
readonly size: number
Current number of items on the stack.
readonly isFull: boolean
Stack full indicator.
readonly isEmpty: boolean
Stack empty indicator.
Internal stack representation.
This property is initialized lazily the first time it is accessed.
After initialization, you cannot change the property value.
Method Injection pattern with the default
If necessary, you can replace the default implementation with your own, for example a linked list or a typed array.
ArgumentNullError - an exception thrown when trying to set the property to
- PropertyAlreadyDefineError - an exception thrown when trying to reinitialize a property.