Created
June 1, 2016 02:10
-
-
Save hbarcelos/e675238994fcacf698f6808530199829 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
'use strict'; | |
var RoundLinkedQueue = function RoundLinkedQueue(maxSize) { | |
this.maxSize = maxSize; | |
this.size = 0; | |
this._root = null; | |
this._last = null; | |
} | |
module.exports = RoundLinkedQueue; | |
RoundLinkedQueue.createNode = function(data, next) { | |
next = next || null; | |
return { | |
data: data, | |
next: next | |
}; | |
}; | |
RoundLinkedQueue.prototype.push = function(data) { | |
var node = RoundLinkedQueue.createNode(data); | |
if (this.size < this.maxSize) { | |
if (this._root === null) { | |
this._last = this._root = node; | |
} else { | |
this._last.next = node; | |
this._last = node; | |
} | |
this.size++; | |
} | |
}; | |
RoundLinkedQueue.prototype.pop = function() { | |
}; | |
RoundLinkedQueue.prototype.first = function() { | |
return this._root.data; | |
}; | |
RoundLinkedQueue.prototype.last = function() { | |
return this._last.data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment