seach_bin(a[10],m);。。引发的血案。

来源:互联网 发布:telnet 端口链接失败 编辑:程序博客网 时间:2024/06/07 12:46
 

#include <iostream>
#include <algorithm>

using namespace std;

int seach_bin(int t[],int k)
{

 int low,high,mid;
 low = 1;
 high = 10;

 while(low <= high)
 {
  mid = (low + high) /2;
  if(k == mid)  return mid;
  else if(k < mid)    high = mid - 1;
        else if(k > mid) low  = mid + 1; 
 }
 return -1;
}

int main()
{
 

 int seach_bin(int t[],int k);
 int i,j,a[10],m;


 cout<<"input data"<<endl;
 for(i = 0; i < 10; i++)
 {
  cin>>a[i];
 }

 cout<<"input you want to seacher"<<endl;
  cin>>m;
 
 sort(a,a+10);

//错误。。求纠正及解释。。

//    int i,j,a[10],m;

//都是INT型的啊。为什么冒出来这么一句。。

//  error:initializing argument 1 of 'int seach_bin(int*,int)'  何解??
  seach_bin(a[10],m);
 
 cout<<"You want to search data position is"<<m<<endl;
 
 for(i = 0; i < 10; i++)
  cout<< a[i]<<"\t";
  
 cout<<endl;
 
return 0;
}

原创粉丝点击