728x90 반응형 Queue3 스택으로 큐 만들기(Create Queue with Stacks) References 아래 링크의 강의 중 Section 20. Two Become One의 내용을 추려 이번 글을 작성하였습니다. The Coding Interview Bootcamp: Algorithms + Data Structures on Udemy Solution const Stack = require("./stack"); class Queue { // whenever you create an instance of a queue, you will automatically generate two stacks and assign it to this queue class. constructor() { this.first = new Stack(); this.second = new Stack(); } add.. 2022. 4. 5. 큐 합치기(Queue Weaving) References 아래 링크의 강의 중 Section 18. Underwater Queue Weaving의 내용을 추려 이번 글을 작성하였습니다. The Coding Interview Bootcamp: Algorithms + Data Structures on Udemy Solution // ./queue.js class Queue { constructor() { this.data = []; } add(record) { this.data.unshift(record); } remove() { return this.data.pop(); } peek() { return this.data[this.data.length - 1]; } } module.exports = Queue; // ./index.js cons.. 2022. 4. 5. 큐(The Queue) References 아래 링크의 강의 중 Section 17. The Queue의 내용을 추려 이번 글을 작성하였습니다. The Coding Interview Bootcamp: Algorithms + Data Structures on Udemy Solution class Queue { constructor() { this.data = []; } add(record) { this.data.unshift(record); } remove() { return this.data.pop(); } } Queue란? 선입선출(FIFO) 방식으로 작동하는 일련의 데이터 모음이다. 아래 그림을 보면 알 수 있듯 새로이 선언한 q에 add method로써 1과 2를 추가하면 1 뒤에 2가 추가된다. 여기서 q.remove(.. 2022. 4. 5. 이전 1 다음 728x90 반응형