-
sort linked list
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
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))