큐 (Queue)

지니씨·2021년 8월 10일
0

자료구조&알고리즘

목록 보기
2/10
  • LIFO 후입 선출

  • 구현

    class Queue {
        #array;
        constructor(arr = []) {
            if(!Array.isArray(arr)) {
                throw new TypeError(`${arr} is not an array`);
            }
            this.#array = arr;
        }
        push(x) {
            return this.#array.push(x);
        }
        pop() {
            return this.#array.shift();
        }
        entries() {
            return this.#array;
        }
    }
    
    var queue = new Queue([1,2,3,4]);
profile
하루 모아 평생 🧚🏻

0개의 댓글