PDA

View Full Version : sort linked list



spywx2003
04-06-2008, 05:23 AM
hello i hope i can find help here , i got a problem with insert method for sorted linked list. the problem is the method puts the smallest value on the list and stops after that ...here is my code


public void insert(Room a)
{

if (first==null)
{
first = new RoomNode(a);
}

else
{
// find the right spot to insert

if ( (first.data).compareTo (a) == -1 )
{
RoomNode tempNode =new RoomNode(a);

first = new RoomNode(first.data, tempNode);
}
else if (a.compareTo (first.data) == -1 )
{
Room temp=first.data;
RoomNode n=new RoomNode(temp);

first=new RoomNode (a,n);

}
else
{
RoomNode L=new RoomNode(a);
}

}


length++;

} // method insert(room))