标签:代码 clu use ++ define while include for main
#include<iostream>
#define N 9
/*折半插入排序*/
void BinarySort(int A[], int n) {
int i,j,low , high ,mid;
for (i = 2; i <= n; ++i) {
A[0] = A[i];
low = 1; high = i - 1;
while (low<high)
{
mid = (low + high) / 2;
if (A[mid] > A[0])
high = mid - 1;
else
low = mid + 1;
}
for (j= i-1; j >= high+1; --j)
A[j + 1] = A[j];
A[high + 1] = 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 };//A[0]"哨兵"
printf("排序前数组\n");
OutPrint(A);
BinarySort(A,N-1);
printf("\n排序后数组\n");
OutPrint(A);
system("pause");
return 0;
}
标签:代码 clu use ++ define while include for main
原文地址:https://www.cnblogs.com/brainstorm-yc/p/11651261.html