Desperate help needed with insertion sort code

Here is my insertion sort code for a doubly linked list that does not work. I cannot figure out why and I've been trying everything for the last 10 hours! Please Please help..

publicvoid insertionSort()

{

Node pointer=head;

while(pointer.next!=null)

{

Node insert=pointer.next;

if (insert.item.compareTo(pointer.item)>0)

{

pointer=pointer.next;

}

else

{

insert.prev.next=insert.next;

insert.next.prev=insert.prev;

if (head.item.compareTo(insert.item)>0)

{

insert.next=head;

insert.prev=null;

head.prev=insert;

head=insert;

}

Node current =head.next;

while (current.item.compareTo(insert.item)<0)

{

current=current.next;

}

insert.next=current;

insert.prev=current.prev;

current.prev.next=insert;

current.prev=insert;

}

}

}

[1546 byte] By [javahockeya] at [2007-11-26 17:12:30]
# 1
There is an algorithms forum - under the Fresh Tools category - and I wonder if it would be better for you to post such a question there.
Tillermana at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 2
You should probably advise what "does not work" means also. Usually helps :0
kikemellya at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 3
What is Node type ? Can you provide me some links to it ? I am totally new to it. Thanks
Sangfroida at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 4
It makes sense tracing it out on paper, running it, the program never ends.
javahockeya at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 5
help, pretty please?
javahockeya at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 6
with sugar on top?
javahockeya at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 7
Cripes. You never heard of debugging? At least you could put some System.out.println() into your code so you can see what it's doing.
DrClapa at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...
# 8
> It makes sense tracing it out on paper, running it,> the program never ends.This means that there is an infinite loop somewhere in your code. Find the loops and put some System.out.println()'s in them to see where it's going wrong.
CaptainMorgan08a at 2007-7-8 23:40:23 > top of Java-index,Java Essentials,New To Java...