#include <stdio.h>
#include <stdlib.h>
void show(int a[],int n);
void BinInsertSort(int a[], int n)
{
int key;
int mid, low, high;
for (int i = 1; i < n; i++)
{
key = a[i];
low = 0;
high = i - 1;
while (low <= high)
{
mid = (low + high) / 2;
if (key < a[mid])
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
for (int j = i - 1; j >= high + 1; j--)
{
a[j + 1] = a[j];
}
a[high + 1] = key;
}
}
int main(void)
{
int a[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 };
show(a, 10);
BinInsertSort(a, 10);
show(a, 10);
system("pause");
return 0;
}
C语言实现折半插入排序算法
最新推荐文章于 2024-08-28 23:11:16 发布