티스토리 뷰
class Node{
constructor(item){
this.item = item;
this.next = null;
}
}
class Stack{
constructor(){
this.topOfStack = null;
this.length = 0;
}
push(item){
const node = new Node(item);
if(this.topOfStack!=null){
node.next = this.topOfStack;
}
this.topOfStack = node;
this.length+=1;
}
pop(){
if(this.length==0)return -1;
const popItem = this.topOfStack;
this.topOfStack = popItem.next;
this.length-=1;
return popItem.item
}
size(){
return this.length;
}
empty(){
if(this.length==0) return 1;
else return 0;
}
top(){
if(this.length==0)return -1;
return this.topOfStack.item;
}
}
728x90
'자료구조 알고리즘 > JavaScript 자료구조 알고리즘' 카테고리의 다른 글
JavaScript) 최소 힙 (0) | 2021.09.16 |
---|---|
JavaScript) 최대 힙 (0) | 2021.09.16 |
JavaScript) 덱 Deque (0) | 2021.09.13 |
JavaScript) 큐 Queue (0) | 2021.09.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- BFS
- 서버점검
- DB 생성
- 그래프
- 최소공통조상
- 투포인터 연습
- 서버개발
- MOD
- 다이나믹프로그래밍
- 개발자면접
- 면접질문
- 롱베케이션
- 로드나인
- create db
- 동적프로그래밍
- node.js
- 투포인터
- 다이나밍프로그래밍
- MySQL
- 은둔청년체험
- 면접비
- create databases;
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함