Complete the code to swap two integers using pointers.
void swap(int *a, int *b) {
int temp = *a;
*a = [1];
*b = temp;
}To swap values, assign the value pointed by b to the location pointed by a.
Complete the condition to check if the first array element is greater than the second array element.
if (arr1[i] [1] arr2[j]) { // swap logic }
We swap when the element in arr1 is greater than the element in arr2.
Fix the error in the loop condition to iterate over the first array.
for (int i = 0; i [1] n; i++) { // processing }
The loop should run while i is less than n to cover all elements from 0 to n-1.
Fill both blanks to complete the nested loops for merging arrays.
for (int i = 0; i [1] n; i++) { for (int j = 0; j [2] m; j++) { if (arr1[i] > arr2[j]) { swap(&arr1[i], &arr2[j]); } } }
Both loops should run from 0 to less than their respective sizes to cover all elements.
Fill all three blanks to complete the function that merges two sorted arrays without extra space.
void merge(int arr1[], int arr2[], int n, int m) {
for (int i = 0; i [1] n; i++) {
if (arr1[i] > arr2[0]) {
[2](&arr1[i], &arr2[0]);
int first = arr2[0];
int k;
for (k = 1; k [3] m && arr2[k] < first; k++) {
arr2[k - 1] = arr2[k];
}
arr2[k - 1] = first;
}
}
}The outer loop runs while i < n. We swap arr1[i] and arr2[0] if needed. The inner loop shifts elements in arr2 while k < m and arr2[k] < first.
