部分有序,某個數的左邊有序。
實現是,假定某個數的左邊都是有序的。將這個數空出,往左比較一直到比他小退出。否則,不停交換位置,將大數後移。最後,將假定的那個數填入交換後的空洞。
public void insertionSort(){
int in, out, temp;
for(out = 1; out < array.length; out++){
temp = array[out];
in = out;
while(in > 0 && array[in -1] >= temp){
a[in] = a[in - 1];
--in;
}
a[in] = temp;
}
}