Skip to content

Instantly share code, notes, and snippets.

@kshirish
Created August 12, 2024 03:48
Show Gist options
  • Save kshirish/47381209e2ca8cb8960a94890af66863 to your computer and use it in GitHub Desktop.
Save kshirish/47381209e2ca8cb8960a94890af66863 to your computer and use it in GitHub Desktop.
// 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