voidShellsort (intA[],intLeftintRight );//A[left] to a[right] sort from small to largevoidShellsort (intA[],intLeftintRight ) { intLen = Right-left +1; intgap,i,j,temp; //the Shell proposes an incremental selection rule N/2,n/4,..., 2,1 for(gap=len/2;gap>0; gap/=2) for(i=left+gap;i<=right;i++) for(J=i-gap;j>=left && A[j]>a[j+gap];j-=gap) {//A[j] and A[j+gap] as a subsequencetemp = A[j];/*when J-=gap A[j],a[j+gap] has been processed*/A[j]= A[j+gap];/*J-=gap only to let it exit this loop, and then select the next child column*/a[j+GAP] =temp; } }/*algorithm Analysis: time-complexity: With the increment of the selection of the shell selection increment rule time complexity of O (N2), Papelnov (Papernov) and Stasevic (Stasevich) proposed 2 K The second side +1,..., 65,33,17,9,5,3,1 where k is greater than or equal to 1 of the integer, 2 of the K-th +1 is less than the length of the sequence to be ordered, at this time the complexity of O (n1.5) space-complexity:o (1 ); The algorithm is not stable.*/
Hill-Sort C + +