Hi,

I have a QVector of QVectors (that is QVector< QVector <int> >. I am trying to write a basic sort algorithm for sorting the collection.
I can't seem to get the while loop right, and I am staring myself blind on it -- so I was wondering if I can get some help.

The outer Vector contains values 0 - 46 and the inner Vector contains positive numbers from 0 to 99.
My goal is to swap rows so that the highest values in the inner Vector come first, but in such a way that the corresponding values (rows) of the outer Vector move along with the swap...
Example: if vec[0][1] < vec[1][1] then swap the values in vec[0][0] and vec[0][1] with values vec[1][0] and vec[1][1] respectively.

Here is my code:
// I am receiving a QVector< QVector< int > > via a function. It is called vecToSort.

QVector< int > vecSwapLow;
QVector< int > vecSwapHigh;

for ( int x = 1; x < vecToSort.size(); x++ ) // row-by-row of outer Vector
{
int iMove = x;
int iHigh0 = vectToSort[ 1 ][ 0 ];
int iHigh1 = vectToSort[ 1 ][ 1 ];
int iLow0 = vectToSort[ 0 ][ 0 ];
int iLow1 = vectToSort[ 0 ][ 1 ];
vecSwapLow.clear()
vecSwapLow << iLow0 << iLow1;

while ( ( iMove > 0 ) && ( vecToSort[ iMove -1 ][ 1 ] > vecToSort[ x ][ 1 ] ) )
{
vecSwapHigh << iHigh0 << iHigh1;
vecToSort.replace( ( iMove - 1 ), vecSwapHigh );
iMove--;
}
vecSwapHigh.clear();
vecToSort.replace( iMove, vecSwapLow );

// after the repetition loop this codes puts the value that was replaced back into the outer Vector
// problem is that if the repetition loop is not executed, it still replaces the row, so I end up with 3 or 4 sorted values and the rest until row 46 is all the same...
}