Skip to content

Instantly share code, notes, and snippets.

@kshirish
Created August 11, 2024 04:44
Show Gist options
  • Save kshirish/9f782d82b9914d51ca72febae2a9a00f to your computer and use it in GitHub Desktop.
Save kshirish/9f782d82b9914d51ca72febae2a9a00f to your computer and use it in GitHub Desktop.
// 2, 8, 10, 4, 3, 6, 7
class Queue {
constructor() {
this.list = [];
this.pointer = 0;
}
enqueue(value) {
this.list.push(value);
}
dequeue() {
this.pointer += 1;
}
printAll() {
for(let index = this.pointer; index < this.list.length; index += 1) {
console.log(this.list[index]);
}
}
}
const queue = new Queue();
queue.enqueue(2);
queue.enqueue(8);
queue.enqueue(10);
queue.enqueue(4);
queue.enqueue(3);
queue.enqueue(6);
queue.enqueue(7);
queue.printAll();
queue.dequeue();
queue.dequeue();
queue.dequeue();
queue.printAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment