class Node {
constructor(value){
this.value = value
this.next = null
}
}
class Stack {
constructor(){
this.top = null
this.bottom = null
this.length = 0
}
peek(){
return this.top;
}
push(value){
const node = new Node(value);
node.next = this.top;
this.top = node;
this.length++;
return this;
}
pop(){
if(!this.top){
return null;
}
if(this.top == this.bottom){
this.bottom = null;
}
this.top = this.top.next;
this.length--;
return this;
}
}
const myStack = new Stack();
myStack.push("google");
myStack.push("udemy");
myStack.push("discord");
//myStack.pop();
//myStack.pop();
//myStack.pop();
myStack.peek();