it’s embarrassing to ask this, but please could you help me adapt this algorithm to a two-dimensional array, so that it sorts the whole matrix across columns? This is an assignment from my university, the deadline is tomorrow and I can’t get anything done. Thank you for your time.
int L, R, imin, imax, tmp;
clock_t time_start, time_stop;
time_start = clock();
L = 0; R = N - 1;
while (L < R) {
imin = L; imax = L;
for (int i = L + 1; i < R + 1; i++) {
if (A[i] < A[imin]) {
imin = i;
}
else {
if (A[i] > A[imax]) {
imax = i;
}
}
}
if (imin != L) {
tmp = A[imin];
A[imin] = A[L];
A[L] = tmp;
}
if (imax != R) {
if (imax == L) {
tmp = A[imin];
A[imin] = A[R];
A[R] = tmp;
}
else {
tmp = A[imax];
A[imax] = A[R];
A[R] = tmp;
}
}
L = L + 1;
R = R - 1;
}
time_stop = clock();
return (time_stop - time_start) * P;
}