Created
August 12, 2024 03:48
-
-
Save kshirish/47381209e2ca8cb8960a94890af66863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2, 8, 10, 4, 3, 6, 7 | |
class Stack { | |
constructor() { | |
this.list = []; | |
this.pointer = 0; | |
} | |
push(value) { | |
this.list.push(value); | |
} | |
pop() { | |
this.list.pop(); | |
} | |
printAll() { | |
for(let index = 0; index < this.list.length; index += 1) { | |
console.log(this.list[index]); | |
} | |
} | |
} | |
const stack = new Stack(); | |
stack.push(2); | |
stack.push(8); | |
stack.push(10); | |
stack.push(4); | |
stack.push(3); | |
stack.push(6); | |
stack.push(7); | |
stack.printAll(); | |
stack.pop(); | |
stack.pop(); | |
stack.pop(); | |
stack.printAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment