标签:shellSort ++i 希尔排序 main print void code efi for
#include<iostream>
#define N 9
#define ElemType int
/*希尔排序*/
void ShellSort(ElemType A[],int n) {
int i,j,dk;
for (dk = n / 2; dk >= 1; dk = dk / 2)
for (i = dk + 1; i <= n; ++i)
if (A[i]<A[i-dk])
{
A[0] = A[i];
for (j = i - dk; j > 0 && A[0] < A[j]; j -= dk)
A[j + dk] = A[j];
A[j + dk] = A[0];
}
}
/*输出数组*/
void OutPrint(int A[]) {
int i;
for (i = 1; i < N; i++)
{
printf("%d ", A[i]);
}
}
int main() {
int A[N] = { -1,48, 62, 35, 77, 55,14,35,98 };
printf("排序前数组\n");
OutPrint(A);
ShellSort(A, N-1);
printf("\n排序后数组\n");
OutPrint(A);
system("pause");
return 0;
}
标签:shellSort ++i 希尔排序 main print void code efi for
原文地址:https://www.cnblogs.com/brainstorm-yc/p/11651407.html