Thread: ordering arrays
View Single Post
Join Date: Oct 2008
Posts: 32
Reputation: emotionalone is an unknown quantity at this point 
Solved Threads: 4
emotionalone emotionalone is offline Offline
Light Poster

Re: ordering arrays

 
0
  #10
Nov 21st, 2008
Do you want to go from the first part of this image to the second part?
Assuming in the first part the values are in a random order and blocks of the same color represent linked data.

http://img300.imageshack.us/my.php?image=errorjm8.jpg

What you do is, again, assume the very first is the lowest and then compare the element of that index to every single other element of the array, in this case 'error' and if there's a lowest value you switch values using an auxiliary variable, yes. In addition to that right after doing that switch and before doing the next comparison you switch the values of all your columns for the 2 rows in 'weights' involved. But, you keep comparing the element of the same index until you've reach the end. And you do this for all elements of 'error'.
So if you first compare element in error of index 0 with index 1, you then compare index 0 with index 2 and even if index 2 is lowest and you do the switch the next comparison will be index 0 and index 3 followed by index 0 and index 4. If 'error' were to have only 5 rows, you would stop the comparisons with index 0. the next comparison would be index 1 and index 2, and so on. The last comparison will have to be index 3 and index 4.

I hope this helps.
Reply With Quote