void InsertionSort(int arr[]) { for(int i=1; i < arr.len(); i++) { int key = arr[i]; int j = i; while(key < arr[j-1] && j > 0) { //move key to previous position arr[j] = arr[j-1]; j--; } arr[j] = key; PrintArray(arr); } }
时间: 2024-12-17 20:57:02
void InsertionSort(int arr[]) { for(int i=1; i < arr.len(); i++) { int key = arr[i]; int j = i; while(key < arr[j-1] && j > 0) { //move key to previous position arr[j] = arr[j-1]; j--; } arr[j] = key; PrintArray(arr); } }