Insertion Sort Algorithm Execution
What is printed after the insertion sort algorithm completes execution?
public class InsertionSortTest {
public static void main(String[] args) {
int[] arr = {5, 2, 9, 1, 5};
for (int i = 1; i < arr.length; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
System.out.println(arr[2]);
}
}
A
9
B
1
C
5
D
2
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | demosolasis1 | 1 | 1 | 0m 56s | 44 |
| #2 | theofanusmischa | 1 | 1 | 1m 11s | 29 |
| #3 | bommasam000 | 1 | 2 | 2m 52s | -82 |
Items per page:
10
1 – 3 of 3
APFIVE