Complete the code to swap two elements in the array.
int temp = arr[[1]]; arr[[1]] = arr[j]; arr[j] = temp;
We use j + 1 to hold the index of the element to swap with j.
Complete the code to compare adjacent elements for swapping.
if (arr[j] [1] arr[j + 1]) { // swap }
We swap if the current element is greater than the next to sort in ascending order.
Fix the error in the inner loop condition to avoid out-of-range errors.
for (int j = 0; j [1] n - i - 1; j++) { // compare and swap }
The inner loop must run while j < n - i - 1 to avoid accessing beyond array bounds.
Fill both blanks to complete the outer loop and array length usage.
int n = arr.[2]; for (int i = 0; i [1] n - 1; i++) { // inner loop }
The outer loop runs while i < n - 1 and array length is accessed by Length in C#.
Fill all three blanks to complete the bubble sort method signature and return statement.
public static int[] [1](int[] arr) { int n = arr.Length; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } return [2]; } // Usage: int[] sorted = BubbleSort([3]);
The method name is BubbleSort, it returns the sorted array arr, and the input array variable is inputArray.
