折半插入排序(限高手交流)函数不能成功调用的问题!!!
void BinaryInsertSort(int a[],int n);是这个函数不能成功调用,别的地方没有问题,高手交流下
#include <iostream>
#include <time.h>
using namespace std;
#define MAX 10
void Create_random_numbers(int l[],int n);
void BinaryInsertSort(int a[],int n);
int main()
{
int A[MAX];
Create_random_numbers(A,MAX);
BinaryInsertSort(A,MAX);
cout<<"排序后输出:";
for(int i=0;i<MAX;++i)
cout<<A[i]<<" ";
cout<<endl;
return 0;
}
void Create_random_numbers(int l[],int n) ////产生n个随机int数,存储在数组a中
{
srand((unsigned)time(NULL)+rand());
for(int i = 0; i<n; ++i)
l[i]=rand();
cout<<"随机产生的"<<n<<"个数为:";
for(i=0;i<n;++i) //回显随机产生的n个数
cout<<l[i]<<" ";
cout<<endl;
}
void BinaryInsertSort(int a[],int n) //对n个元素的数组a进行排序
{
for(int i=1;i<n;++i)
{
int low=0,high=i-1;
int mid,temp;
while(low<=high&&low>=0)
{
mid=(low+high)/2;
if(a[mid]<=a[i])
{
if(a[i]<=a[mid+1])
{
temp=a[i];
for(int j=i-1;j>=mid+1;--j)
a[j+1]=a[j];
a[mid+1]=temp;
}
else
low=mid+1;
}
else
{
if(a[mid-1]<=a[i])
{
temp=a[i];
for(int j=i-1;j>=mid;--j)
a[j+1]=a[j];
a[mid]=temp;
}
else
high=mid-1;
}
}
}
}