#include <iostream>
using namespace std;
const int N = 100010;
int q[N];
void xier_sort(int q[],int n){
for(int i = n / 2 ; i > 0; i--){
for(int j = 0; j + i < n; j++){
for(int k = 1; j + i * k < n; k++){
if(q[j + i * (k - 1)] > q[j + i * k]) swap(q[j + i * (k - 1)],q[j + i * k]);
}
}
}
}
int main(){
int n;
scanf("%d",&n);
for(int i =0 ;i<n;i++){
scanf("%d",&q[i]);
}
xier_sort(q,n);
for(int i =0 ;i<n;i++){
printf("%d ",q[i]);
}
return 0;
}
希尔排序实现
最新推荐文章于 2024-11-12 21:59:57 发布