插入排序:基于数组的表
package Crabime;
/*this program aims at sorting the program in quicksort method*/
public class ArrayQuickSort{
private static int unsortedIndex;
private static int location;
private static int temp;
public static int[] quicksort(int[] a){
//check Array whether a bigger than 1
if(a.length < 1) return a;
//get the first outoforder number
for(int i=1; i < a.length; i++){
if(a[i-1] > a[i]){
unsortedIndex = i;
location = unsortedIndex;
temp = a[unsortedIndex];
while(location>0 && a[location-1] > temp){
a[location] = a[location-1];
location--;
}
a[location] = temp;
}
}
return a;
}
public static void main(String[] args){
int[] a = {10, 11, 12, -1, 9, 19};
quicksort(a);
for(int i=0; i < a.length; i++){
System.out.print(a[i] + " ");
}
}
}