Created
July 25, 2021 20:52
-
-
Save giovanisleite/48ea9cace3f7da22a4485337ae429817 to your computer and use it in GitHub Desktop.
Data Structure: 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.queue = [] | |
} | |
get length() { | |
return this.queue.length; | |
} | |
enqueue(el) { | |
this.queue.push(el) | |
} | |
dequeue() { | |
return this.queue.shift() | |
} | |
peek() { | |
return this.queue[0] | |
} | |
isEmpty() { | |
return this.length === 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment