Simple stack implementation on ES6
npm install --save stack-data
- in constructor
new Stack(1,"2",3,[4, 5],6); - via
push(elem)method
Also supports chaining mechanism like:
newStack().push(1).push(2).push(3).push(4)// creates object with 4 elements 1,2,3,4// Examples of using stack-data//Added stack elements in constructorletpreInitStack=newStack(1,"2",3,[4,5],6);preInitStack.size;//5//Added elements classically via push()letstack=newStack();stack.size;//0stack.push(1).push("2");stack.size;//2stack.pop();//"2"stack.size;//1stack.peek();//1stack.size;//1push - Pushes element into stack. Throws an StackException when parameter is empty.
Required
Type: Object
elem - object which will be putted into stack
pop - Takes top element from the stack. Throws an StackException when the stack is empty.
peek - Peeks at the top element of the stack. Throws an StackException when the stack is empty.
size - Returns the size of the stack.
MIT © Aleksandr Filatov greybax@gmail.com