#include
#include
using namespace std;
int HalfSearch(const vector &a, const int& x, int low, int high)
{
if(low > high)
return -1;
int mid = (low + high)/2;
cout<<(char)a[mid]< if(a[mid] < x)
return HalfSearch(a, x, mid + 1, high);
else if(a[mid] > x)
return HalfSearch(a, x, low, mid - 1);
else
return mid;
}
int Search(const vector& a, const int& x)
{
return HalfSearch(a, x, 0, a.size() - 1);
}
void main()
{
vector v;
v.push_back('b');
v.push_back('c');
v.push_back('d');
v.push_back('e');
v.push_back('f');
v.push_back('g');
v.push_back('h');
v.push_back('i');
v.push_back('j');
v.push_back('k');
Search(v, 1);
}
打印结果:f c b
阅读(585) | 评论(0) | 转发(0) |