class Node{
constructor(value){
this.data = value;
this.next = null;
}
}
class Stack{
constructor()
{
this.length = 0;
this.top = null;
}
push(value)
{
let newNode = new Node(value);
if(this.top==null)
this.top = newNode;
else
{
newNode.next = this.top;
this.top = newNode;
}
this.length++;
}
pop()
{
let temp = this.top;
this.top = temp.next;
this.length--;
return temp.data;
}
peek(){
return this.top.data;
}
}
let obj = new Stack();
obj.push('google');
obj.push('udemy');
obj.push('satellite');
console.log(obj.pop());
console.log(obj.peek());