Created
August 11, 2024 04:44
-
-
Save kshirish/9f782d82b9914d51ca72febae2a9a00f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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