We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9ab4569 commit bc91d88Copy full SHA for bc91d88
insertion_sort.md
@@ -1,26 +1,22 @@
1
Insertion Algorithm
2
========================
3
+- Stable
4
+- O(1) extra space
5
+- O(n2) comparisons and swaps
6
+- Adaptive: O(n) time when nearly sorted
7
+- Very low overhead
8
-Implementations:
-
-[INSERTIONSORT]
-```
9
-//Stable
10
-//O(1) extra space
11
-//O(n2) comparisons and swaps
12
-//Adaptive: O(n) time when nearly sorted
13
-//Very low overhead
+```java
14
void insertionSort(int [] numbers) {
15
for(int i = 1; i < numbers.length; i++) {
16
int val = numbers[i];
17
int j = i - 1;
18
- while(j >= 0 && numbers[j] > val){
+ while (j >= 0 && numbers[j] > val) {
19
numbers[j + 1] = numbers[j];
20
j--;
21
}
+
22
numbers[j + 1] = val;
23
24
25
26
-[/INSERTIONSORT]
+```
0 commit comments