Skip to content

Instantly share code, notes, and snippets.

@HamidReazaNikoonia
Created February 18, 2022 05:59
Show Gist options
  • Save HamidReazaNikoonia/31adcfe1341a044c66aa541f19228a26 to your computer and use it in GitHub Desktop.
Save HamidReazaNikoonia/31adcfe1341a044c66aa541f19228a26 to your computer and use it in GitHub Desktop.
JavaScript Data Structures - Queue
// 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