/* This code implement the insertion sorting algorithm. We assume that the array will be sorted in the ascending order. a[0] compare a[0] and a[1], and insert a[1] in its correct postion compare a[k] with the sorted list a[0], ..., a[k-1], and insert it in the correct position Gang Qu Feb. 18, 2021 */ #include #define SIZE 10 void printArray(int a[], int n) { int i; for(i=0; i=0 && key < a[j]) { a[j+1] = a[j]; printf("\t j=%d: ", j); j--; printArray(a, i+1); } a[j+1] = key; printf("after insert %3d: ", key); printArray(a, i+1); printf("\n"); } printf("After sorting: "); printArray(a, SIZE); return 0; }