Click to See Complete Forum and Search --> : Linked list problem


Lysander
10-22-2003, 09:57 PM
This hangs when I run it:

public void remove(Node foo)
{
if (foo==start)
{
if (start.next!=null)
{
start=start.next;
}
}
else
{
remover(start, start.next, foo);
}
}


public void remover(Node nodeprev, Node nodecurr, Node test)
{
if (nodecurr.contents.equals(test.contents))
{
if (nodecurr.next!=null)
{
nodeprev.next=nodecurr.next;
nodecurr=null;
}
else {nodecurr=null;}
}
else if (nodecurr.next!=null)
{remover(nodecurr, nodecurr.next, test);}
}

public void sort(ListClass list)
{
MyInteger x=new MyInteger(0);
Node curNode=list.start;
ListClass List2=new ListClass();
Node tmpSmallest=new Node(x, null);
while( (list.start)!=null )
{
while( curNode.next!=null )
{
MyInteger y=(MyInteger)curNode.contents;
if (y.lessThan(tmpSmallest.contents))
{tmpSmallest=curNode;}
if (curNode.next!=null)
{curNode=curNode.next;}
}
List2.addAfter(tmpSmallest);
list.remove(tmpSmallest);
}
pa2.output2.setText(List2.toString());
}

Anyone see why?

Lysander
10-22-2003, 10:09 PM
This is obviously not all of it; if you want to see more, I'll post the full source if necessary.

ArchAngel
10-26-2003, 04:08 AM
You method names and variables are less than helpful. I suggest you do things like renaming 'foo', 'x', 'y' and 'test' to something helpful and also choose a better name for 'remover' - the method's function is less than obvious (some JavaDoc would help).

The definitions of your other classes would help.