public static int[] insertionSort(int[] B) {
int n = B.length;
for (int i = 1; i < n; i++) {
int temp = i;
int j = i;
while(j > 0 && temp < B[j-1]){
B[j] = B[j-1];
j--;
}
B[j] = temp;
}
return B;
}
书上的比喻:就像打扑克时起牌,来一张排一张。
起的牌比手上最后一张小就和前面一张比一直比到比手上的牌大或比到最前头。