How to change the following sorting algorithm to operate on a single array arr[]? For now, I have to transfer elements from one array arr[] to res[]. How to preform all operations on arr[]? Here is my code:
void main(){
int arr [] = {1, 14, 5, 18, 3, 1};
int res [] = {0, 0, 0, 0, 0, 0};
int x = 0;
int y = 0;
for(int i = 0; i < 6; i++) {
x = 0;
for(int k = 0; k < 6; k++){
if(arr[k] > x){
x = arr[k];
y = k;
}
}
arr[y] = 0;
res[5 - i] = x;
}
for (int z = 0; z < 6; z++){
printf("%d ", res[z]);
}
}