Quick actions

cmd+k|ctrl+k

Navigation

Languages

Queue Using Stack

Snippet info

Language

JavaScript

Visibility

public

Author

kishorrathva8298

Created

2022-04-09T22:03:54.830506Z

Updated

2022-04-09T22:03:54.830506Z

class Queue {
  constructor() {
    this.array = [];
  }

  peek() {
    return this.array[this.array.length - 1];
  }
  push(value) {
    this.array.unshift(value);
  }
  pop() {
    return this.array.pop();
  }
  empty() {
    return !this.array.length;
  }
}

const queue = new Queue();

queue.push(1);
queue.push(2);
console.log(queue);
console.log(queue.peek());
console.log(queue.pop());
console.log(queue.empty());
INFO