❓ 큐(Queue) 란?

  • 스택과 반대로 먼저 넣은 데이터가 먼저 나오는 FIFO(First In First Out)기반의 선형 자료 구조이다.

💡 구현 메서드

Queue()

function Queue(array) {
  this.array = array ? array : [];
}

생성자 함수로 초기 데이터 설정

데이터 전체 획득 : Queue.getBuffer()

Queue.prototype.getBuffer = function () {
  return this.array.slice();
};

객체 내 데이터 셋 반환

비어 있는지 확인 : Queue.isEmpty()

Queue.prototype.isEmpty = function () {
  return this.array.length === 0;
};

객체 내 데이터가 있는지 확인

데이터 추가 : Queue.enqueue()

Queue.prototype.enqueue = function (element) {
  return this.array.push(element);
};

데이터 추가

데이터 삭제 : Queue.dequeue()

Queue.prototype.dequeue = function () {
  return this.array.shift();
};

데이터 삭제

첫번째 데이터 : Queue.front()

Queue.prototype.front = function () {
  return this.array.length === 0 ? undefined : this.array[0];
};

가장 첫 데이터 반환

사이즈 : Queue.size()

Queue.prototype.size = function () {
  return this.array.length;
};

큐 내 데이터 개수 확인

전체 삭제 : Queue.clear()

Queue.prototype.clear = function () {
  this.array = [];
};

큐 초기화

profile
#UXUI #코린이

0개의 댓글