Constructor
new Stack()
Example
const stack = new Collections.Stack();
// FOR ALL EXAMPLES BELOW. ASSUME stack IS CLEARED BEFORE EACH EXAMPLE
Methods
clear() → {undefined}
Empties the Stack
Returns:
- Type
- undefined
peek() → {*}
Reports but does not remove the staged element to be removed next
Example
stack.push(1);
stack.peek() // returns 1 but does not remove it
Returns:
The element staged to be removed next
- Type
- *
pop() → {*}
Removes data from stack in a last in first out manner
Example
stack.push(1).push(2).push(3);
stack.pop(); // 3
Returns:
The reomved data
- Type
- *
push(data) → {Stack}
Pushes the given data onto the stack
Example
stack.push(1).push(2); // <2, 1>
Parameters:
Name | Type | Description |
---|---|---|
data |
data | The data to push onto stack |
Returns:
The instance this method was called
- Type
- Stack
size() → {number}
Reports the size of the queue
Returns:
The size of the queue
- Type
- number