스택(Stack)
0. 요약
0-1. 연결 리스트로 스택 구현하기
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
class Stack {
constructor() {
this.top = null;
this.bottom = null;
this.size = 0;
}
// 스택에 원소 추가하기
push(data) {
const node = new Node(data);
if (this.size === 0) this.bottom = node;
else node.next = this.top;
this.top = node;
this.size++;
}
// 스텍에 원소 제거하기
pop() {
const topNode = this.top;
if (!topNode) return null;
this.top = topNode.next;
this.size--;
if (this.size === 0) this.bottom = null;
return topNode;
}
// 스택에 쌓인 가장 마지막 원소 가져오기
peek() {
return this.top;
}
}0-2. 배열로 스택 구현하기
1. 개요
2. 스택이란?

3. 연결 리스트로 스택 구현하기
3-1. 노드와 스택의 기본 구조
3-2. 스택에 원소 추가하기
3-3. 스텍에 원소 제거하기
3-4. 스택에 쌓인 가장 마지막 원소 가져오기
4. 배열로 스택 구현하기
4-1. 스택의 기본 구조
4-2. 스택에 원소 추가하기
4-3. 스택에 원소 제거하기
4-4. 스택에 쌓인 가장 마지막 원소 가져오기
5. 스택의 시간 복잡도
Big-O (시간복잡도)
삽입
삭제
검색
6. Conclusion
참고
Last updated