最近在学数据结构和算法,靠印象敲了里面的代码时:想模拟有序向量的查找,终端没反应,是时间太久还是没跳出循环?
#include<iostream>
using namespace std;
template <typename T>
int binsearch(T*A,T const &e,int low,int high)
{
while(low<high)
{
int mi=(low+high)/2;
(e<A[mi])?high=mi:low=mi;
}
return --low;
}
int main()
{
int num[]={1,5,8,13,19,28,35,89,99,100};
int k=13;
cout<<binsearch(num,k,0,10)<<endl;
}