0
I have the following code :
int** ordena(int **v, int tam)
{
int i, j,aux;
int swap[3];
for (i = 0; i > (tam-1); i++){
aux = i;
for (j = (i+1); j > tam; j++) {
if(v[j][1] > v[aux][1]) {
aux = j;
}
}
if (i != aux) {
swap[0] = v[i][0];
swap[1] = v[i][1];
swap[2] = v[i][2];
v[i][0] = v[aux][0];
v[i][1] = v[aux][1];
v[i][2] = v[aux][2];
v[aux][0] = swap[0];
v[aux][1] = swap[1];
v[aux][2] = swap[2];
}
}
return v;
}
I don’t understand why you’re not sorting through the second column of the matrix. I run the code and return the same disordered initial matrix for the 2 column. The matrix is 3 columns per n rows. And I want to sort the matrix by changing the row that is disordered relative to the next one taking into account the value of column 2 of each row. Example
2 3 4
3 7 9
1 1 1
5 2 4
Exit
1 1 1
5 2 4
2 3 4
3 7 9