折半查找(二分查找)
主要不会写main函数
望各位大神帮忙解决,谢谢!!!!!!
#include "stdio.h"
#include "malloc.h"
#define TRUE 1
typedef int Keyelem;
typedef struct
{
Keyelem key;
int length;
}SortedSeq;
int binarySearch(int *SortedSeq,int KeyData,int Sortedlength)
{
int low=0,mid,high=Sortedlength-1;
while(low<=high)
{
mid=(low+high)/2;
if(KeyData==SortedSeq[mid])
{
return mid;
}
else if(KeyData<SortedSeq[mid])
{
return high=mid-1;
}
else if(KeyData>SortedSeq[mid])
{
return high=mid+1;
}
else{ return mid;}
return 0;
}
}
int main()
{
int KeyData;
int binarySearch;
int array[]={11,12,13,14,15,16,17,18,19};
int target=3;
int location;
/* main函数的输出为这些
printf("二分查找的查找位置为: ");
printf("二分查找的次数为:");
*/
}