43 lines
684 B
C
43 lines
684 B
C
|
#include <stdio.h>
|
||
|
|
||
|
void print(int *arr, int N) {
|
||
|
for (int i = 0; i < N; i++) {
|
||
|
printf("%d,", arr[i]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
|
||
|
void shellSort(int *arr, int N) {
|
||
|
int j, key;
|
||
|
for (int gap = N / 2; gap > 0; gap /= 2) {
|
||
|
// insertion sort, with gaps
|
||
|
for (int i = gap; i < N; i++) {
|
||
|
key = arr[i];
|
||
|
j = i;
|
||
|
|
||
|
// remember to compare with gaps
|
||
|
while (j >= gap && arr[j - gap] < key) {
|
||
|
arr[j] = arr[j - gap];
|
||
|
j -= gap;
|
||
|
}
|
||
|
arr[j] = key;
|
||
|
}
|
||
|
print(arr, N);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(void) {
|
||
|
int N;
|
||
|
|
||
|
scanf("%d", &N);
|
||
|
int arr[N];
|
||
|
|
||
|
for (int i = 0; i < N; i++) {
|
||
|
scanf("%d,", &arr[i]);
|
||
|
}
|
||
|
|
||
|
shellSort(arr, N);
|
||
|
|
||
|
return 0;
|
||
|
}
|