일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 역행자
- 블록체인
- JavaScript
- node.js
- 최강의 인생
- SQL
- Algorithms
- select
- 정규표현식
- Programmers
- 자바스크립트
- array.push()
- 배열
- 코딩테스트
- for문
- array.slice()
- MySQL
- 프로그래머스
- array
- 코드스테이츠
- Developer_JoyKim
- 코딩공부
- 재귀함수
- join
- Hackerrank
- Where
- 알고리즘
- 개발자의 책장
- 코플릿
- 개발자_조이킴
Archives
- Today
- Total
CodingSpace
[자료구조] 큐 (Queue) 본문
Queue
먼저 삽입된 데이터가 먼저 나오는 FIFO(First In First Out) 구조로
잘 알려진 자료구조이다.
너비 우선 탐색 (Breadth First Search, BFS)를 구현하는데 사용된다.
코드 구현
자료구조 Queue를 javascript 코드로 구현하면 아래와 같다.
// javascript로 구현한
// 자료구조 Queue
class Queue {
constructor() {
this.queue = [];
this.head = 0;
this.rear = 0;
}
// 삽입
enqueue(value) {
this.rear++;
this.queue[this.rear] = value;
}
// 제거
dequeue() {
const value = this.queue[this.front];
delete this.queue[this.front];
this.front = this.front + 1;
}
// 큐가 비어있는지
isEmpty() {
return this.head === this.rear;
}
}
References.
- 코딩테스트 광탈 방지 A to Z: JavaScript (이선협)
For Developer.
- 잘못되거나 부족한 부분이 있다면 언제든지 댓글 부탁드립니다 :)
'자료구조 및 알고리즘' 카테고리의 다른 글
[알고리즘] - 아레토스테네스의 체 (소수 찾기) (0) | 2023.05.29 |
---|---|
[자료구조] 힙 (Heap) (0) | 2023.04.24 |
Comments