LIFO Data structure

Extends Instance Properties
PropertyTypeDefault ValueDescription
countNumber

the current number of elements in this queue

isEmptyBoolean

true if this queue is empty

valuesArray

a copy of the values contained in this queue

Constructor

Defined collections/Stack.js

clear Function Public


Defined collections/Stack.js

Removes all items from this stack.

Source
function (){
   this.__stack.length = 0;
   this.__next = -1;
           
}
    

contains Function Public


Defined collections/Stack.js

Determine if this stack contains the element

Arguments Returns Source
function (obj){
   return this.__stack.indexOf(obj) !== -1;
           
}
    

peek Function Public


Defined collections/Stack.js

Retrieves the item at the tail of the stack without removing it

Returns Source
function (){
   var next = this.__next,
       ret;
   if (next >= 0) {
       ret = this.__stack[next];
   }
   return ret;
           
}
    

pop Function Public


Defined collections/Stack.js

Removes the tail of this static

Returns Source
function (){
   var next = this.__next,
       ret,
       stack;
   if (next >= 0) {
       stack = this.__stack;
       ret = stack[next];
       stack[this.__next--] = undefined;
   }
   return ret;
           
}
    

push Function Public


Defined collections/Stack.js

Add an item to the tail of this stack

Arguments Source
function (data){
   this.__stack[++this.__next] = data;
           
}
    

remove Function Public


Defined collections/Stack.js

Removes an element from this stack.

Arguments Returns Source
function (obj){
   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;
           
}
    

License

MIT https://github.com/C2FO/comb/raw/master/LICENSE

Meta