Skip to content

Instantly share code, notes, and snippets.

@kingsleytan
Last active October 8, 2019 05:10
Show Gist options
  • Save kingsleytan/da421711d53cdb66905f132ba7395aca to your computer and use it in GitHub Desktop.
Save kingsleytan/da421711d53cdb66905f132ba7395aca to your computer and use it in GitHub Desktop.
Example of Queue in JS, hosted with ❤ by GitHub
function Queue() {
var collection = [];
this.print = function () {
console.log(collection);
}
this.enqueue = function (element) {
collection.push(element);
}
this.dequeue = function () {
return collection.shift();
}
this.front = function () {
return collection[0];
}
this.isEmpty = function () {
return collection.length === 0;
}
this.size = function () {
return collection.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment