Basically i have to do what it says in the title.for example if
arr1 = {18,19,4,11}
arr2 = {1,2,3,4}
after sorting
arr2 = {2,1,4,3}
Basically i have to sort arr2 in descending order based on arr1.
Ive tried doing it with the bubble sort method but something keeps going wrong. Here is my code
for(i = 0; i < k; i++)
{
for(j = 0; j < k+1; j++)
{
if(arr1[i] < arr1[j])
{
temp = arr2[i];
arr2[i] = arr2[j];
arr2[j] = temp;
}
}
}
Yes, and I just explained. In your code you are only changing arr2, but arr1 stays the same, so...it doesn't sort correctly, it just goes back and forth on each pass.