#include "iostream"
void shellsort(int data[],int n);
int main()
{
int number=9;
int data[]={5,6,4,8,2,3,7,9,1};
int i;
for (i=0;i<number;i++){
printf("%d",data[i]);
}
printf("\n");
shellsort(data,number);
printf("\n");
for (i=0;i<number;i++){
printf("%d",data[i]);
}
printf("\n");
system("PAUSE");
return 0;
}
void shellsort(int data[],int n){
int jup;
jup=n/2;
int i,j;
int temp;
while(jup!=0){
for (i=jup;i<n;i++){
temp=data[i];
j=i-jup;
while (temp<data[j] && j>=0){
data[j+jup]=data[j];
j=j-jup;
}
data[j+jup]=temp;
j=j-jup;
}
jup=jup/2;
}
}
沒有留言:
張貼留言