Created
September 26, 2012 01:56
-
-
Save codeimpossible/3785559 to your computer and use it in GitHub Desktop.
simple queue data structure
This file contains hidden or 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
var queue = new (function(undefined){ | |
var _q = [], _size = 0; | |
this.push = function(task) { | |
_q.push(task); | |
_size++; | |
return task; | |
}; | |
this.next = function() { | |
_size--; | |
return _q.shift(); | |
}; | |
this.peek = function() { | |
return _q[0] || undefined; | |
}; | |
this.getLength = function() { | |
return _size; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment