文章
20
粉丝
412
获赞
13
访问
165.3k
#include <iostream>
using namespace std;
void shellSort(int arr[], int n) {
int gap = n / 2;
while(gap >= 1) {
for(int i = gap;i < n;i++) {
int j = 0;
int temp = arr[i];
for(j = i-gap;j >= 0 && temp < arr[j]; j -= gap)
arr[j+gap] = arr[j];
arr[j+gap] = temp;
}
gap /= 2;
}
}
int main() {
int n, arr[1005];
cin >> n;
for(int i = 0;i < n;i++)
cin >> arr[i];
shellSort(arr, n);
for(int i = 0;i < n;i++)
cout << arr[i] << " ";
cout << endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发