MCPcopy Create free account
hub / github.com/OI-wiki/OI-wiki / insertionSort

Method insertionSort

docs/basic/code/insertion-sort/insertion-sort_1.java:1–11  ·  view source on GitHub ↗
(int[] arr)

Source from the content-addressed store, hash-verified

1public static void insertionSort(int[] arr) {
2 for (int i = 1; i < arr.length; i++) {
3 int key = arr[i];
4 int j = i - 1;
5 while (j >= 0 && arr[j] > key) {
6 arr[j + 1] = arr[j];
7 j--;
8 }
9 arr[j + 1] = key;
10 }
11}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected