티스토리 뷰
class Node{
constructor(item){
this.item = item;
this.next = null;
}
}
class Queue{
constructor(){
this.head = null;
this.tail = null;
this.length = 0;
}
push(item){
const node = new Node(item)
if(this.head==null){
this.head= node;
}else{
this.tail.next = node;
}
this.tail = node;
this.length +=1;
}
pop(){
const popItem = this.head;
this.head = this.head.next;
this.length -=1;
return popItem.item;
}
size(){
return this.length;
}
empty(){
if(this.length==0){
return 1;
}else{
return 0;
}
}
front(){
if(this.empty()==1) return -1;
return this.head.item;
}
back(){
if(this.empty()==1) return -1;
return this.tail.item;
}
}
728x90
'자료구조 알고리즘 > JavaScript 자료구조 알고리즘' 카테고리의 다른 글
JavaScript) 최소 힙 (0) | 2021.09.16 |
---|---|
JavaScript) 최대 힙 (0) | 2021.09.16 |
JavaScript) 덱 Deque (0) | 2021.09.13 |
JavaScript) 스택 Stack (0) | 2021.09.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 로드나인
- DB 생성
- 최소공통조상
- create db
- 동적프로그래밍
- 서버개발
- BFS
- 면접비
- 은둔청년체험
- 투포인터 연습
- 다이나믹프로그래밍
- 서버점검
- node.js
- MySQL
- 롱베케이션
- create databases;
- MOD
- 면접질문
- 투포인터
- 개발자면접
- 그래프
- 다이나밍프로그래밍
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함