line 22: look VERY closely...you have something extra there that makes it not do what you think...
why are you not going all the way to the end in your sort? As written, you will be leaving the last element in place. You should see this when you print out your final array. you probably want your line 29 to be
why are you only swapping if they are equal? Shouldn't you swap if one is less than (or greater than, depending on which way you want to sort) the other?>
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Welcome to the Ranch
I recommend you search for utilityclass, and you will find this. Now create yourself a utility class like that, and give it a swapTwoElementsInArray() method. You pass the array and the indices of the two values, then you can put the swapping code in that method, and it is available for re-use.
Joined: Oct 13, 2005
Why have you altered your original post? That makes the replies look like nonsense