Skip to content

Instantly share code, notes, and snippets.

@Bjacksonshorts
Created September 30, 2013 03:47
Show Gist options
  • Save Bjacksonshorts/6759157 to your computer and use it in GitHub Desktop.
Save Bjacksonshorts/6759157 to your computer and use it in GitHub Desktop.
function Queue() {
this.tail = null;
this.head = null;
}
Queue.prototype.enqueue = function(n) {
//this.head = n;
//n.getNextNode = this.tail;
if(this.head == null){
this.head = n;
return this.head;
}
else{
this.tail = n;
return this.tail;
}
}
Queue.prototype.dequeue = function(n) {
n = this.head;
if( n != null){
this.head = null;
this.tail = n;
}
return this.tail;;
}
Queue.prototype.peek = function(n) {
return this.head;
}
Queue.prototype.getLength = function(n) {
var counter = 0;
if(this.head != null){
counter++;
}
return counter;
}
@cangevine
Copy link

getLength: there is an infinite loop when you only check the head of the Queue. instead, check each specific node with a local variable (call it n).
only enqueue should take a parameter
enqueue does not need to return anything
More comments from our discussion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment