react-use-stack
v1.2.1
Published
``` Stack data structure as npm package This package helps you to simulate the behaviour of a stack. If you are familiar with c++ stacks this has exactly same methods. ```
Downloads
8
Maintainers
Readme
What is this ?
Stack data structure as npm package
This package helps you to simulate the behaviour of a stack.
If you are familiar with c++ stacks this has exactly same methods.
Installation
npm i react-use-stack
Methods
push()
Use - For inserting/pushing data to stack
if you want to push say 1,2,3
stack.push(1)
stack.push(2)
stack.push(3)
pop()
Use - For removing data from stack
stack.pop()
This is follow the property of stack and pop the last element
If there are no element it returns -1 and if popped will return 1
size()
Use - To get the current size of the stack
stack.size()
isEmpty()
Use - To check if the stack is empty or not
stack.isEmpty()
Front
Use - To get the top element of the stack
stack.top()
This returns "empty" if stack is empty else returns the element
Example
Showing adding 4 elements, printing and removing all
const stack = require('react-use-stack');
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
while(!stack.isEmpty()){
console.log(stack.top());
stack.pop();
}