Re: sort multiple reference

Basically you are rearranging each of the matrices rows according to the sorted ordering of a given column in a given matrix.

You just need to figure out what is the new row index of each of the rows.

If you alter you data structure a bit, it should be easy.

Keep on each element 2 values:

a. The actual value of the element

b. The index of the __original__ row of the element.

Before beginning the sort process - initialize the row indices(b) of all elements in the given column.

After the sort (by element value(a) ) is complete, just linearly go over the column elements and the (b) index of the element on row i will tell you which row should be moved to row i.

PS. If you do not wish to alter the data structure, just fill an array of size N with the indices 0 to N-1 and duplicate each sort operation you do on the matrix onto it (equivalent to adding another column of sorted numbers to the matrix).

Kind regards,

Zachi