Last active
October 8, 2019 05:10
-
-
Save kingsleytan/da421711d53cdb66905f132ba7395aca to your computer and use it in GitHub Desktop.
Example of Queue in JS, hosted with ❤ by GitHub
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
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