-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-stack-using-array.js
More file actions
41 lines (28 loc) · 860 Bytes
/
3-stack-using-array.js
File metadata and controls
41 lines (28 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
================================================================
What is Stack:
-------------------
A LIFO data structure.
The last element added to the stack will be the first element
removed from the stack.
Where stacks are used?
------------------------
1) Managing function invocationn
2) Undo/Redo
3) Routing (the history obbject) is treated like a stack
Note:
------
There are many more ways to implement a stack.
================================================================
*/
let stack = [];
stack.unshift("First Item");
stack.unshift("Second Item");
stack.unshift("Third Item");
stack.unshift("Fourth Item");
stack.unshift("Fifth Item");
console.log(stack);
// ["Fifth Item", "Fourth Item", "Third Item", "Second Item", "First Item"]
stack.shift();
console.log(stack);
// ["Fourth Item", "Third Item", "Second Item", "First Item"]