카테고리 없음
queue
cghun
2020. 12. 6. 21:07
class Queue {
constructor() {
this.storage = {};
this.front = 0; //맨앞
this.rear = 0; //맨뒤
}
size() {
return this.rear - this.front;
}
//0 1 2 3
// pop()
// rear = 3
// 0 1 2
//두개가 생성됬을떄 front
enqueue(element) {
this.storage[this.rear] = element;
this.rear =this.rear+1;
}
dequeue() {
let result = this.storage[this.front];
delete this.storage[this.front];
if(this.front < this.rear){
this.front++;
}
return result;
}
}
module.exports = Queue;