Class comb.collections.Stack
Extends
comb.collections.Collection.
LIFO Data structure
Defined in: Stack.js.
- Methods borrowed from class comb.collections.Collection:
- concat, indexOf, join, lastIndexOf, slice, toString
Field Detail
{Number}
count
the current number of elements in this queue
{Boolean}
isEmpty
true if this queue is empty
{Array}
values
a copy of the values contained in this queue
Method Detail
clear()
Removes all items from this stack.
this.__stack.length = 0;
this.__next = -1;
{Boolean}
contains(obj)
Determine if this stack contains the element
- Parameters:
- {*} obj
- the object to find
- Returns:
- {Boolean} true if this stack contains the element
return this.__stack.indexOf(obj) != -1;
{*}
peek()
Retrieves the item at the tail of the stack without removing it
- Returns:
- {*} The element at the tail of the stack. Returns undefined if the stack is empty.
var ret = undefined,next = this.__next;
if (next >= 0) {
ret = this.__stack[next];
}
return ret;
{*}
pop()
Removes the tail of this static
- Returns:
- {*} the data at the tail of this stack
var ret = undefined, stack, next = this.__next;
if (next >= 0) {
stack = this.__stack;
ret = stack[next];
stack[this.__next--] = undefined;
}
return ret;
push(data)
Add an item to the tail of this stack
- Parameters:
- {*} data
- item to qppend to this stack
this.__stack[++this.__next] = data;
{Boolean}
remove(obj)
Removes an element from this stack.
- Parameters:
- {*} obj
- the data to remove.
- Returns:
- {Boolean} true if the element was removed, false otherwise.
var index = this.__stack.indexOf(obj), ret = false;
if (index != -1) {
if (index == this.__next) {
this.pop();
} else {
this.__stack.splice(index, 1);
this.__next--;
}
ret = true;
}
return ret;
Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jan 31 2012 16:14:12 GMT-0600 (CST)