스택은 "후입선출(LIFO: Last-In-First-Out)" 원칙을 따르는 선형 자료구조입니다. 이는 가장 최근에 삽입된 항목이 가장 먼저 제거된다는 의미입니다. 스택을 실생활에 비유하자면 책상 위에 쌓인 책더미와 같습니다. 새로운 책은 맨 위에 놓이고, 책을 꺼낼 때도 맨 위에서부터 꺼내게 됩니다.

push(item): 스택의 맨 위에 항목을 추가합니다.
pop(): 스택의 맨 위 항목을 제거하고 반환합니다.
peek() 또는 top(): 스택의 맨 위 항목을 반환하지만 제거하지는 않습니다.
isEmpty(): 스택이 비어있는지 확인합니다.
size(): 스택에 있는 항목의 개수를 반환합니다.
👉 구현은 push와 pop만 했습니다.
class Node{
constructor(value){
this.value = value;
this.next = null;
}
}
class Statk{
constructor(){
this.first = null;
this.last = null;
this.size = 0;
}
push(val){
var newNode = new Node(val);
if(!this.first){
this.first = newNode;
this.last = this.first;
}else{
var temp = this.first;
this.first = newNode;
this.first.next = temp;
}
return ++this.size;
}
pop(){
if(!this.first) return null;
var temp = this.first;
if(this.first === this.last){
this.last = null;
}
}
}