GATE | GATE-CS-2015 (Mock Test) | Question 11
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]); } } |
chevron_right
filter_none
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}
Answer: (A)
Explanation: The function sorts the array in waveform. See Sort an array in wave form for more details.
Quiz of this Question
Recommended Posts:
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 13
- GATE | GATE-CS-2015 (Mock Test) | Question 14
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 16
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 10
- GATE | GATE-CS-2015 (Mock Test) | Question 2
- GATE | GATE-CS-2015 (Mock Test) | Question 17
- GATE | GATE-CS-2015 (Mock Test) | Question 4
- GATE | GATE-CS-2015 (Mock Test) | Question 5
- GATE | GATE-CS-2015 (Mock Test) | Question 10
- GATE | GATE-CS-2015 (Mock Test) | Question 10
- GATE | GATE-CS-2015 (Mock Test) | Question 8
- GATE | GATE-CS-2015 (Mock Test) | Question 9



