Created
February 26, 2020 01:57
-
-
Save o-henry/027b0baa11fbdfe9baaf6397c047b49a to your computer and use it in GitHub Desktop.
Queue
This file contains 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
class Queue { | |
constructor() { | |
this._arr = []; | |
} | |
enqueue(item) { | |
this._arr.push(item); | |
} | |
dequeue() { | |
return this._arr.shift(); | |
} | |
} | |
const queue = new Queue(); | |
queue.enqueue(1); | |
queue.enqueue(2); | |
queue.enqueue(3); | |
queue.dequeue(); // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment