Title Description
Given a data sequence, Hill sorting algorithm used in descending order.
Gap spacer sequence length until cycle 1 divided by 2
Entry
The first input line t, t test expressed exemplary
second input row n, represents an example of the data has n (n> 1)
of the third row of n data inputs, are both positive integers, with spaces between the data separator open
so
Export
Each set of test data, output per trip sorting result. Different groups are separated by a blank line between the test data.
Sample input
2 6 111 22 6 444 333 55 8 77 555 33 1 444 77 666 2222
Sample Output
444 333 55 111 22 6 444 333 111 55 22 6 444 555 666 2222 77 77 33 1 666 2222 444 555 77 77 33 1 2222 666 555 444 77 77 33 1
prompt
#include<iostream> #include<cstring> using namespace std; #define INF 0x7f int n; int array[INF]; void printarray() { for(int i=0;i<n;i++) { if(i!=n-1) cout<<array[i]<<" "; else cout<<array[i]<<endl; } } void Shellsort() { int i,j,gap; int temp; for(gap=n/2;gap>0;gap/=2) { for(i=gap;i<n;i++) { temp=array[i]; for(j=i;j>=gap&&array[j-gap]<temp;j-=gap) { array[j]=array[j-gap]; } array[j]=temp; } printarray(); } } int main() { int T; cin>>T; while(T-- ) { CIN >> n-; Memset (Array, 0 , the sizeof (Array)); for ( int I = 0 ; I <n-; I ++ ) CIN >> Array [I]; Shellsort (); COUT < < endl; } return 0 ; } // entirely modeled sorting line, into the gap 1