Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Queue = function (){
- this.oldStack = new Stack ();
- this.newStack = new Stack ();
- }
- Queue.prototype.add = function (value){
- this.newStack.push(value);
- }
- Queue.prototype.size = function (){
- return this.oldStack.size + this.newStack.size;
- }
- Queue.prototype.sync = function (){
- if (this.oldStack.isEmpty()){
- while(!this.newStack.isEmpty()){
- this.oldStack.push(this.newStack.pop());
- }
- }
- }
- Queue.prototype.peek = function (){
- this.sync();
- return this.oldStack.peek();
- }
- Queue.prototype.remove = function (){
- this.sync();
- return this.oldStack.pop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement