java插入排序Insert sort實例
複製程式碼如下://直接插入排序void DirectInsertionSort(int* arr, int nLen){int i, j;for (i=1; i<nLen; i++){int temp = arr[i];for (j=i-1; j> =0; j--){if (temp < arr[j])arr[j+1] = arr[j];elsebreak;}if (j+1 != i)arr[j+1] = temp; //注意這裡是j+1}}//折半插入排序void BinaryIns
2025-01-07