I need to know if I'm writing this sort function correctly. that sort's an array of #'s into descending order while maintaining the link up of another array of numbers.
For example, a set of data for array will look like this:
Arr[]={ 4, 2, 1, 5, 3}
And a set of data for array2 will look like this:
Arr2[]={ 780, 600, 1900, 690, 1200}
All of the numbers are coming from a data file.
I need it too look something like this:
Arr1: Arr2:
5 690
4 780
3 1200
2 600
1 1900
Can someone show me please? Thank you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void sort1array(int arr[],int arr2[],int arr3 [],int arr4 [],int k){
int temp,pass,cand;
for (int i = 0;i<k-1;i++){
for(cand =0;cand<k-1;cand++){
if(arr[cand]>arr[cand+1]){
int temp = arr [cand+1];
arr [cand+1] = arr [cand];
arr [cand ] = temp;
}
}
}
return;
}
I tried removing one of them but once I remove them, I get really weird outputs but swapping them twice gets me the output I want. it's just line 17 that gets weird