0%
0 / 25 answered

Practice Test 6

25 Questions
Question
1 / 25
Q1

You are implementing insertion sort for a small classroom tool that sorts quiz scores. The program reads $n$ integers into an array (unsorted), then sorts ascending using insertion sort. It must use iteration with a for loop for the outer pass and a while loop to shift elements. Input: first line $n$, second line $n$ integers. Output: the sorted array on one line separated by spaces. Constraints: $1 \le n \le 50$; values are in $-1000, 1000$.

Given the task requirements, which of the following correctly implements the required inner loop structure?


for (int i = 1; i < arr.length; i++) {

    int key = arr<u>i</u>;

    int j = i - 1;

    // inner loop here

}

Question Navigator