Class Index | File Index

Classes


Class 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 a container.
Defined in: <../buckets.js>.

Class Summary
Constructor Attributes Constructor Name and Description
 
Creates an empty Stack.
Method Summary
Method Attributes Method Name and Description
 
add(elem)
Pushes an item onto the top of this stack.
 
Removes all of the elements from this stack.
 
contains(elem, equalsFunction)
Returns true if this stack contains the specified element.
 
forEach(callback)
Executes the provided function once per element present in this stack in LIFO order.
 
Checks if this stack is empty.
 
peek()
Looks at the object at the top of this stack without removing it from the stack.
 
pop()
Removes the object at the top of this stack and returns that object.
 
push(elem)
Pushes an item onto the top of this stack.
 
size()
Returns the number of elements in this stack.
Class Detail
buckets.Stack()
Creates an empty Stack.
Method Detail
{boolean} add(elem)
Pushes an item onto the top of this stack.
Parameters:
{Object} elem
The element to be pushed onto this stack.
Returns:
{boolean} true If the element was pushed or false if it is undefined.

clear()
Removes all of the elements from this stack.

{boolean} contains(elem, equalsFunction)
Returns true if this stack contains the specified element.

If the elements inside this stack are not comparable with the === operator, a custom equals function must be provided to perform searches, the 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 to check if two elements are equal.
Returns:
{boolean} True if this stack contains the specified element, false otherwise.

forEach(callback)
Executes the provided function once per element present in this stack in LIFO order.
Parameters:
{function(Object):*} callback
Function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false inside the callback.

{boolean} isEmpty()
Checks if this stack is empty.
Returns:
{boolean} True if and only if this stack contains no items; false otherwise.

{*} peek()
Looks at the object at the top of this stack without removing it from the stack.
Returns:
{*} The object at the top of this stack or undefined if the stack is empty.

{*} pop()
Removes the object at the top of this stack and returns that object.
Returns:
{*} The object at the top of this stack or undefined if the stack is empty.

{boolean} push(elem)
Pushes an item onto the top of this stack.
Parameters:
{Object} elem
The element to be pushed onto this stack.
Returns:
{boolean} True if the element was pushed or false if it is undefined.

{number} size()
Returns the number of elements in this stack.
Returns:
{number} The number of elements in this stack.

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Sep 17 2014 02:43:23 GMT-0500 (COT)