Skip to content

Instantly share code, notes, and snippets.

@hbarcelos
Created June 1, 2016 02:10
Show Gist options
  • Save hbarcelos/e675238994fcacf698f6808530199829 to your computer and use it in GitHub Desktop.
Save hbarcelos/e675238994fcacf698f6808530199829 to your computer and use it in GitHub Desktop.
'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