# include<stdio.h> # include<windows.h> void ShellSort(int * arr, int n); int main(void) { ?? ?int arr[] = {8, 5, 10, 3, 15, 1, 6, 2, 12}; ?? ?int n = sizeof(arr)/sizeof(int); ?? ?ShellSort(arr, n); ?? ?for(int i = 0; i < n; i++) ?? ?{ ?? ??? ?printf("%d ", arr[i]); ?? ?} ?? ?printf("\n"); ?? ?system("pause"); ?? ?return 0; } void ShellSort(int * arr, int n) { ?? ?for(int inc = n/2; inc > 0; inc /= 2) ?? ?{ ?? ??? ?for(int i = inc; i < n; i++) ?? ??? ?{ ?? ??? ??? ?int temp = arr[i]; ?? ??? ??? ?int j = i - inc; ?? ??? ??? ?while(j >= 0 && temp < arr[j]) ?? ??? ??? ?{ ?? ??? ??? ??? ?arr[j+inc] = arr[j]; ?? ??? ??? ??? ?j -= inc; ?? ??? ??? ?} ?? ??? ??? ?arr[j+inc] = temp; ?? ??? ?} ?? ?} }
|