#include <iostream>
#include <string>
#include <vector>
#include <ctype.h>
using namespace std;

int main()
{
	vector<int> v1;
	vector<int>::iterator start;
	vector<int>::iterator end;
	vector<int>::iterator mid;
	int loop = 0;
	int key = 11;
	for (loop = 0; loop < 10; ++loop)
	{
		v1.push_back(loop);
	}

	start = v1.begin();
	end = v1.end();
	

	while(start < end)
	{
		mid = start + (end - start)/2;
		if(*mid == key)
		{
			cout<< mid - v1.begin();
			return 0;
		}		
		else if(*mid > key)
		{
			end = mid;
		}
		else
		{
			start = mid + 1;
		}
	}
	cout << "can not find the matched value"<<endl;
	return -1;
}

  

相关文章:

  • 2021-12-03
  • 2021-12-03
  • 2022-12-23
  • 2021-06-08
  • 2021-12-10
  • 2021-12-10
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案