all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,11 @@
public static void insertSort(int[] A){
for(int i = 1; i < A.length; i++){
int value = A[i];
int j = i - 1;
while(j >= 0 && A[j] > value){
A[j + 1] = A[j];
j = j - 1;
}
A[j + 1] = value;
}
}

View file

@ -0,0 +1,14 @@
public static <E extends Comparable<? super E>> void insertionSort(List<E> a) {
for (int i = 1; i < a.size(); i++) {
int j = Math.abs(Collections.binarySearch(a.subList(0, i), a.get(i)) + 1);
Collections.rotate(a.subList(j, i+1), j - i);
}
}
public static <E extends Comparable<? super E>> void insertionSort(E[] a) {
for (int i = 1; i < a.length; i++) {
E x = a[i];
int j = Math.abs(Arrays.binarySearch(a, 0, i, x) + 1);
System.arraycopy(a, j, a, j+1, i-j);
a[j] = x;
}
}