Complete the code to swap two integers using a temporary variable.
void swap(int *a, int *b) {
int temp = *a;
*a = [1];
*b = temp;
}The value pointed by b is assigned to the location pointed by a to complete the swap.
Complete the condition to continue the outer loop for bubble sort.
for (int i = 0; i [1] n - 1; i++) { // inner loop }
The outer loop runs from 0 up to n-2, so the condition is i < n - 1.
Fix the error in the inner loop condition to avoid out-of-bound access.
for (int j = 0; j [1] n - i - 1; j++) { if (arr[j] > arr[j + 1]) { swap(&arr[j], &arr[j + 1]); } }
The inner loop must run while j < n - i - 1 to avoid accessing arr[j + 1] out of bounds.
Fill both blanks to complete the bubble sort nested loops correctly.
for (int i = 0; i [1] n - 1; i++) { for (int j = 0; j [2] n - i - 1; j++) { if (arr[j] > arr[j + 1]) { swap(&arr[j], &arr[j + 1]); } } }
Both loops use the less than < operator to iterate correctly within array bounds.
Fill all three blanks to complete the bubble sort function that sorts an array in ascending order.
void bubbleSort(int arr[], int n) {
for (int i = 0; i [1] n - 1; i++) {
for (int j = 0; j [2] n - i - 1; j++) {
if (arr[j] [3] arr[j + 1]) {
swap(&arr[j], &arr[j + 1]);
}
}
}
}The outer and inner loops use < to stay within bounds, and the comparison uses > to swap when the left element is greater than the right.
