Selection sort for linked list

Hey, Im writing a selectionSort method for a circular doubly linked list. I posted the code below, but I got something wrong because it gets stuck in an infinit loop and doesnt do anything.... So my logic must be bad somewere. I have it built into my LinkedList class so thats why there arnt any parms coming in and why I can refer to fields in the sort directly. It compiles fine so no compileling errors just the infinit loop.
Thanks
public void selectionSort()//built into LinkedList class so dont need parms
		{
			Node curPos;
			Node indexSmallest; 
			Node start;
			Node temp;
			for (start = this.head, curPos = this.head.next; start != null; )
			{
				indexSmallest = start;
				for (curPos = start, curPos = this.head.next; curPos != null; )
				{
					if (indexSmallest.compareTo(curPos) > 0)
					{
						indexSmallest = curPos;
					}
				} // end for
				temp = start;
				start = indexSmallest;
				indexSmallest =  temp;
			} // end for       
		}

Open in new window

theldroAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
>                         start = indexSmallest;

looks like that should be:

                        start = curPos;
0
Mick BarryJava DeveloperCommented:
and you don't actually do a swap, all you change is local vars. You need to instead swap the data attached to the nodes

0
theldroAuthor Commented:
I changed the part you said, Im sure that was a problem too, but the sort gets stuck in the infinit loop before that I think. I think the problem might be that I have a bad comparTo()  method. The comparTo()  method works fine for my BubbleSort, but I think its a problem for selection sort. Im not sure though so heres the method. I feel like a retard asking all these questions, sorry if they sound stupid.
Thanks
public class DLL implements Comparable<Node>//implementing comparable interface.
{
....

        public int compareTo(Node that) 
        {
        return ((Comparable)this.head).compareTo((Comparable)   that.data);
        }
			
			
			
}

Open in new window

0
Mick BarryJava DeveloperCommented:
thats not the compareTo that is being called, but the problems not there

you don't update curPos each iteration

                        for (curPos = start; curPos != null; )
                        {
                              if (indexSmallest.compareTo(curPos) > 0)
                              {
                                    indexSmallest = curPos;
                              }
                                        curPos = curPos.next;
                        } // end for
                                // swap data between start and indexSmallest

                                // get ready for next loop

                                 start = start.next;

                               
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
theldroAuthor Commented:
Thanks for helping me so much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.