We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 534b054 + 0534c14 commit 1af0c0bCopy full SHA for 1af0c0b
sorting/InsertionSort.java
@@ -0,0 +1,27 @@
1
+/**
2
+* Generic Insertion Sort
3
+* @author Jan Tabacki
4
+*/
5
+
6
+public class InsertionSort<T extends Comparable<? super T>> {
7
8
+ /**
9
+ * Sort
10
+ * @param T[] array of not sorted elements
11
+ * @return T[] array of sorted element
12
+ */
13
+ public T[] Sort(T[] values) {
14
+ if (values.length > 0) {
15
+ T value = values[0];
16
+ for (int i = 1; i < values.length; ++i) {
17
+ value = values[i];
18
+ int j;
19
+ for (j = i - 1; j >= 0 && values[j].compareTo(value) > 0; --j) {
20
+ values[j + 1] = values[j];
21
+ }
22
+ values[j + 1] = value;
23
24
25
+ return values;
26
27
+}
0 commit comments