728x90
2021.09.14 - [Programming/자료구조] - 스택 Stack
스택 Stack
이번에 소개할 자료구조는 스택과 큐인데 스택 따로 큐 따로 2개에 나눠서 소개하겠습니다. 그리고 그중에서 스택 부터 보도록 하겠습니다. 1. 스택 소개 스택(Stack)은 데이터를 쌓아올린듯한 자
bamtory29.tistory.com
스택의 원리나 구조에 대해서는 위의 포스트를 참조해주세요.
class Node {
constructor(data, nextNode = null) {
this.data = data;
this.nextNode = nextNode;
}
}
class Stack {
constructor() {
this.top = null;
this.size = 0;
}
push(data) {
const newNode = new Node(data);
newNode.nextNode = this.top;
this.top = newNode;
this.size++;
}
pop() {
if (this.top === null) {
return false;
}
this.top = this.top.nextNode;
this.size--;
}
peak() {
return this.top.data;
}
}
https://github.com/Bam-j/algorithm-study/blob/main/study-code/data-structure/Stack.js
GitHub - Bam-j/algorithm-study: 블로그 알고리즘 정리 포스트 코드 수록 + 코딩 테스트 코드 수록
블로그 알고리즘 정리 포스트 코드 수록 + 코딩 테스트 코드 수록. Contribute to Bam-j/algorithm-study development by creating an account on GitHub.
github.com
728x90
'Programming > 자료구조' 카테고리의 다른 글
[Javascript] 이진 탐색 트리 (0) | 2021.11.18 |
---|---|
[Javascript] 큐 (0) | 2021.11.18 |
[Javascript] 연결 리스트 (0) | 2021.11.17 |
그래프 탐색 - 너비 우선 탐색 BFS (0) | 2021.10.09 |
그래프 탐색 - 깊이 우선 탐색 DFS (0) | 2021.10.08 |
댓글