c
void ShellSort(int arr[], int n) {//希尔排序--升序
int i = 0;
int j = 0;
int d = n / 2;
for (d = n / 2;d >= 1;d /= 2) {
for (i = d;i < n;i++) {
int tmp = arr[i];
for (j = i;j >= 0;j -= d) {
if (tmp < arr[j - d]) {
arr[j] = arr[j - d];
}
else {
arr[j] = tmp;
break;
}
}
}
}
}
int main() {
int arr[10] = { 3,5,2,9,1,4,8,6,10,7 };
int n = 10;
ShellSort(arr, 10);
for (int i = 0;i < 10;i++) {
printf("%d ", arr[i]);
}
return 0;
}