Object buckets.Stack

A Stack is a Last-In-First-Out (LIFO) data structure, the last element added to the stack will be the first one to be removed. This implementation uses a linked list as the underlying storage.

Object Summary
Constructor Name and Description
Creates an empty Stack.
Method Summary
Method Name and Description
buckets.Stack.add(elem)
Pushes an element onto the top of the stack.
buckets.Stack.clear()
Removes all the elements from the stack.
buckets.Stack.contains(elem, equalsFunction)
Returns true if the stack contains the specified element.
buckets.Stack.equals(other, equalsFunction)
Returns true if the stack is equal to another stack.
buckets.Stack.forEach(callback)
Executes the provided function once per element present in the stack in LIFO order.
buckets.Stack.isEmpty()
Checks if the stack is empty.
buckets.Stack.peek()
Returns the element at the top of the stack without removing it.
buckets.Stack.pop()
Removes the element at the top of the stack and returns it.
buckets.Stack.push(elem)
Pushes an element onto the top of the stack.
buckets.Stack.size()
Returns the number of elements in the stack.
buckets.Stack.toArray()
Returns an array containing all the elements in the stack in LIFO order.
Object Detail
buckets.Stack()
Creates an empty Stack.
Method Detail
<static> {boolean} buckets.Stack.add(elem)
Pushes an element onto the top of the stack. Equivalent to push.
Parameters:
{Object} elem
The element.
Returns:
{boolean} true If the element was pushed or false if it's undefined.

<static> buckets.Stack.clear()
Removes all the elements from the stack.

<static> {boolean} buckets.Stack.contains(elem, equalsFunction)
Returns true if the stack contains the specified element.

If the elements inside the stack are not comparable with the === operator, a custom equals function must be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:

var petsAreEqualByName = function(pet1, pet2) {
 return pet1.name === pet2.name;
}
Parameters:
{Object} elem
Element to search for.
{function(Object|Object):boolean=} equalsFunction
Optional function used to check if two elements are equal.
Returns:
{boolean} True if the stack contains the specified element, false otherwise.

<static> {boolean} buckets.Stack.equals(other, equalsFunction)
Returns true if the stack is equal to another stack. Two stacks are equal if they have the same elements in the same order.
Parameters:
{buckets.Stack} other
The other stack.
{function(Object|Object):boolean=} equalsFunction
Optional function to check if two elements are equal. If the elements in the stacks are custom objects you should provide a custom equals function, otherwise the === operator is used to check equality between elements.
Returns:
{boolean} True if the stack is equal to the given stack.

<static> buckets.Stack.forEach(callback)
Executes the provided function once per element present in the stack in LIFO order.
Parameters:
{function(Object):*} callback
Function to execute, it's invoked with an element as argument. To break the iteration you can optionally return false inside the callback.

<static> {boolean} buckets.Stack.isEmpty()
Checks if the stack is empty.
Returns:
{boolean} True if and only if this stack contains no elements, false otherwise.

<static> {*} buckets.Stack.peek()
Returns the element at the top of the stack without removing it.
Returns:
{*} The element at the top of the stack or undefined if the stack is empty.

<static> {*} buckets.Stack.pop()
Removes the element at the top of the stack and returns it.
Returns:
{*} The element at the top of the stack or undefined if the stack is empty.

<static> {boolean} buckets.Stack.push(elem)
Pushes an element onto the top of the stack.
Parameters:
{Object} elem
The element.
Returns:
{boolean} True if the element was pushed or false if it's undefined.

<static> {number} buckets.Stack.size()
Returns the number of elements in the stack.
Returns:
{number} The number of elements in the stack.

<static> {Array.<*>} buckets.Stack.toArray()
Returns an array containing all the elements in the stack in LIFO order.
Returns:
{Array.<*>} An array containing all the elements in the stack in LIFO order.