스택 Stack
class Node {
constructor(value){
this.valeue = value;
this.next = null;
}
}
class Stack {
construtor(){
this.first = null;
this.last = null;
this.size = 0;
}
push(val){
let newNode = new Node(val);
if(!this.first){
this.first = newNode
this.last = newNode;
}else{
let temp = this.first;
this.first = newNode;
this.first.next = temp;
}
return ++this.size;
}
pop(){
if(!this.first) return null;
let temp = this.first;
if(this.first === this.last){
this.last = null;
}
this.first = this.first.next;
this.size--;
return temp.value;
}
}
const test = new Stack()
test.push(1);
test.push(2);
test.push(3);
test.pop();
console.log(test,"확인중@@")