빈칸을 채워넣어 Queue를 구현하는 문제이다.
class Queue {
constructor() {
this.storage = {};
this.front = 0;
this.rear = 0;
}
size() {
return 'FILL_ME_IN';
}
// 큐에 데이터를 추가 할 수 있어야 합니다.
enqueue(element) {
this.storage['FILL_ME_IN'] = element;
this.rear += 1;
}
// 가장 먼저 추가된 데이터가 가장 먼저 추출되어야 합니다.
dequeue() {
// 빈 큐에 dequeue 연산을 적용해도 에러가 발생하지 않아야 합니다
if (this.size() === 0) {
return;
}
const result = this.storage['FILL_ME_IN'];
delete this.storage['FILL_ME_IN'];
this.front += 1;
return result;
}
}