function Queue() {
this._inStack = [];
this._outStack = [];
}
Queue.prototype.enqueue = function(value) {
this._inStack.push(value);
};
Queue.prototype.dequeue = function() {
if (this._outStack.length) {
return this._outStack.pop();
}
while (this._inStack.length) {
this._outStack.push(this._inStack.pop());
}
return this._outStack.length ? this._outStack.pop() : undefined;
};
Queue.prototype.getSize = function() {
return this._inStack.length + this._outStack.length;
}
Queue.prototype.peek = function() {
if (this._outStack.length) {
return this._outStack[this._outStack.length-1];
}
while (this._inStack.length) {
this._outStack.push(this._inStack.pop());
}
return this._outStack.length ? this._outStack[this._outStack.length - 1] : undefined;
};
Queue.prototype.isEmpty = function() {
return (this._inStack.length + this._outStack.length) === 0;
};