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
  1. function (){
  2. this.__stack.length = 0;
  3. this.__next = -1;
  4. }

contains Function Public


Defined collections/Stack.js

Determine if this stack contains the element

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

peek Function Public


Defined collections/Stack.js

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

Returns Source
  1. function (){
  2. var next = this.__next,
  3. ret;
  4. if (next >= 0) {
  5. ret = this.__stack[next];
  6. }
  7. return ret;
  8. }

pop Function Public


Defined collections/Stack.js

Removes the tail of this static

Returns Source
  1. function (){
  2. var next = this.__next,
  3. ret,
  4. stack;
  5. if (next >= 0) {
  6. stack = this.__stack;
  7. ret = stack[next];
  8. stack[this.__next--] = undefined;
  9. }
  10. return ret;
  11. }

push Function Public


Defined collections/Stack.js

Add an item to the tail of this stack

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

remove Function Public


Defined collections/Stack.js

Removes an element from this stack.

Arguments Returns Source
  1. function (obj){
  2. var index = this.__stack.indexOf(obj), ret = false;
  3. if (index !== -1) {
  4. if (index === this.__next) {
  5. this.pop();
  6. } else {
  7. this.__stack.splice(index, 1);
  8. this.__next--;
  9. }
  10. ret = true;
  11. }
  12. return ret;
  13. }

License

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

Meta