Let swap() be a function that swaps two elements using their addresses.…
Let swap() be a function that swaps two elements using their addresses. Consider the following C function.
void fun (int arr [], int n )
{
for (int i = 0; i < n; i+=2)
{
if (i>0 && arr[i-1] > arr[i])
swap(&arr[i], &arr[i-1]);
if (i<n-1 && arr[i] < arr[i+1])
swap(&arr[i], &arr[i+1]);
}
}
If an array {10, 20, 30, 40, 50, 60, 70, 80} is passed to the function, the array is changed to
- A.
{20, 10, 40, 30, 60, 50, 80, 70}
- B.
{10, 30, 20, 40, 60, 50, 80, 70}
- C.
{10, 20, 30, 40, 50, 60, 70, 80}
- D.
{80, 70, 60, 50, 40, 30, 20, 10}
Attempted by 83 students.
Sign up free to check your answer
Sign up freeLoading lesson…

