#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define Max 11
int main(){
int length;
cout<<"input the length:";
cin>>length;
int data[length+1];
cout<<"input the array:";
for(int i=1;i<=length;i++){
int a;
cin>>a;
data[i]=a;
}
int d;
cout<<"input the d -1 stop"<<endl;
cin>>d;
while(d!=-1){
for(int j=1;j<=d;j++){
int data2[length];
int k=0;
for(int i=j;i<=length;i+=d){
data2[++k]=data[i];
}
for(int o=1;o<k;o++){
for(int oo=o+1;oo<=k;oo++){
if(data2[oo]<data2[o]){
int temp=data2[oo];
data2[oo]=data2[o];
data2[o]=temp;
}
}
}
int t=0;
for(int i=j;i<=length;i+=d){
data[i]=data2[++t];
}
}
cout<<"print:"<<endl;
for(int k=1;k<=length;k++){
cout<<data[k]<<" ";
}
cout<<endl;
cout<<"input the d -1 stop"<<endl;
cin>>d;
}
}
//49 38 65 97 76 13 27 49
c语言数据结构--希尔排序
最新推荐文章于 2024-10-01 23:05:47 发布