/*Description: The insertion sort method takes a value from the front end of the unordered second half and inserts the appropriate position of the first half of the sorted part, with a simple concept but no speed. One of the basic principles to speed up sorting is to make the last order as far as possible, taking advantage of the results of the previous sort to speed up the sorting process, which is based on this concept to improve the insertion ordering method. Solution: Slightly*/#include<stdio.h>#include<stdlib.h>#include<time.h>#defineMAX 10#defineSWAP (x, y) {int t; t = x; x = y; y = t;}voidShellsort (int[]);intMainvoid){ intNumber[max] = {0}; inti; Srand (Time (NULL)); printf ("before sorting: \ n"); for(i =0; i < MAX; i++) {Number[i]= rand ()% -; printf ("%d", Number[i]); } shellsort (number); //System ("pause"); return 0;}voidShellsort (intnumber[]) { intI, J, K, Gap, T; Gap= MAX/2; printf ("\ n Sort after: \ n"); while(Gap >0){ for(k =0; K < Gap; k++){ for(i = k + gap; i < MAX; i + =Gap) { for(j = i-gap; J >= k; J-=Gap) { if(Number[j] > number[j +Gap]) {SWAP (number[j], number[j+Gap]); } Else{ Break; } }}} printf ("\ n gap =%d:", GAP); for(i =0; i < MAX; i++) {printf ("%d", Number[i]); } printf ("\ n"); Gap/=2; }}
"Improved insert Sort"