8000 + implementation of generic InsertionSort.java · AllAlgorithms/java@44737f8 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 44737f8

Browse files
committed
+ implementation of generic InsertionSort.java
1 parent 534b054 commit 44737f8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sorting/InsertionSort.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class InsertionSort<T extends Comparable<? super T>> {
2+
public T[] Sort(T[] values) {
3+
if (values.length > 0) {
4+
T value = values[0];
5+
for (int i = 1; i < values.length; ++i) {
6+
value = values[i];
7+
int j;
8+
for (j = i 5FC8 - 1; j >= 0 && values[j].compareTo(value) > 0; --j) {
9+
values[j + 1] = values[j];
10+
}
11+
values[j + 1] = value;
12+
}
13+
}
14+
return values;
15+
}
16+
}

0 commit comments

Comments
 (0)
0