Forked from anotheremily/Queue Implementation in JavaScript
Created
January 15, 2014 10:02
-
-
Save psiborg/8433724 to your computer and use it in GitHub Desktop.
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() { | |
this.reset(); | |
} | |
Queue.prototype.dequeue = function () { | |
if (this.empty() !== true) { | |
this.length -= 1; | |
return this.items.shift(); | |
} | |
return undefined; | |
}; | |
Queue.prototype.enqueue = function (item) { | |
this.items.push(item); | |
this.length += 1; | |
return true; | |
}; | |
Queue.prototype.empty = Stack.prototype.empty; | |
Queue.prototype.reset = Stack.prototype.reset; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment