Stack
Aashish Panchal
Posted on October 16, 2020
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class Stack {
constructor(){
this.first = null;
this.last = null;
this.size = 0;
}
// Add a new Value in the list
push(val){
var newNode = new Node(val);
if(!this.first){
this.first = newNode;
this.last = newNode;
} else {
var temp = this.first;
this.first = newNode;
this.first.next = temp;
}
console.log(`--> You are ${++this.size} Inserted Value and this is a <- ${val}`);
}
// Delet end value in the list
pop(){
if(!this.first) return null;
var temp = this.first;
if(this.first === this.last){
this.last = null;
}
this.first = this.first.next;
this.size--;
return temp.value;
}
}
var stack = new Stack()
stack.push("Java Script")
stack.push("Java")
stack.push("Html")
stack.push("Css")
💖 💪 🙅 🚩
Aashish Panchal
Posted on October 16, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
opensource RoSctober Fest Wrap-Up: A Month of Code, Community, and Sloth Points! 🦥
November 13, 2024
hacktoberfest ✨ From Contributor to Core Project Maintainer: My Open Source Journey ✨
October 11, 2024
hacktoberfestchallenge My Hacktoberfest 2024 Journey: A Month of Code, Growth, and Unforgettable Lessons 🚀
November 1, 2024