-
Notifications
You must be signed in to change notification settings - Fork 0
Stack
HeechanYang edited this page Jan 1, 2019
·
15 revisions
Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).
Top node of stack.
Size of stack.
Push the node with a value in the stack.
Pop the top node of the stack.
Return value of the top node of the stack.
Return size of the stack.
Check the stack is empty.
Clear the stack.
npm i @structure-js/datastructure
let Stack = require('@structure-js/datastructure').Stack;
let stack = new Stack();
stack.push(3);
stack.push(1);
stack.push(13);
stack.push(12);
stack.push(7);
stack.push(9);
console.log("stack.top() : " + stack.top());
console.log("stack.size() : " + stack.size());
stack.top() : 9
stack.size() : 6
Then it would be like this.
[Image 1]
### Next, Let's `pop` each values.let str = "";
str += stack.pop() + "\t";
str += stack.pop() + "\t";
str += stack.pop() + "\t";
str += stack.pop() + "\t";
console.log(str);
console.log("stack.top() : " + stack.top());
console.log("stack.size() : " + stack.size());
9 7 12 13
stack.top() : 1
stack.size() : 2
Then, It would be like this
[Image 1]