❓ 큐(Queue)
- 먼저 넣은 데이터가 먼저 나오는 FIFO(First In First Out) 기반의 선형 자료 구조이다.
function Queue(array) {
this.array = array ? array : [];
};
✏️ 구현 메서드(Method)
📗 getBuffer() : 객체 내 데이터 셋 반환
Queue.prototype.getBuffer = function () {
return this.array.slice();
};
📗 isEmpty() : 객체 내 데이터 있는지 없는지
Queue.prototype.isEmpty = function () {
return this.array.length === 0;
};
📗 enqueue() : 데이터 추가
Queue.prototype.enqueue = function (element) {
return this.array.push(element);
};
📗 dequeue() : 데이터 삭제
Queue.prototype.dequeue = function() {
return this.array.shift();
};
📗 front() : 가장 첫 데이터 반환
Queue.prototype.front = function () {
return this.array.length == 0 ? undefined : this.array[0];
};
📗 size() : 큐 내 데이터 개수 확인
Queue.prototype.size = function () {
return this.array.length;
};
📗 clear() : 큐 초기화
Queue.prototype.clear = function () {
this.array = [];
};