Created
February 18, 2022 05:59
-
-
Save HamidReazaNikoonia/31adcfe1341a044c66aa541f19228a26 to your computer and use it in GitHub Desktop.
JavaScript Data Structures - 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
// Implement Queue in JS and store collection as Array ( use Array method for add and remove items ) | |
class Queue { | |
constructor() { | |
this.collections = []; | |
} | |
enqueue(item) { | |
this.collections.push(item); | |
} | |
dequeue() { | |
return this.collections.shift(); | |
} | |
getFront() { | |
return this.collections[0] || undefined; | |
} | |
getSize() { | |
return this.collections.length; | |
} | |
isEmpty() { | |
return ( this.collection.length === 0 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment