728x90 반응형 stacks2 스택으로 큐 만들기(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. 스택(Stacks) References 아래 링크의 강의 중 Section 19. Stack 'Em Up With Stacks의 내용을 추려 이번 글을 작성하였습니다. The Coding Interview Bootcamp: Algorithms + Data Structures on Udemy Solution class Stack { constructor() { this.data = []; } push(record) { this.data.push(record); } pop() { return this.data.pop(); } peek() { return this.data[this.data.length - 1]; } } // const s = new Stack(); // s.push(1); // s.push(2); // .. 2022. 4. 5. 이전 1 다음 728x90 반응형