#include<iostream>
#include<vector>
using namespace std;
using std::vector;
int main()
{
vector<int> text{54,87,575,4587,54245,54255,58655,59654,60000,60555,65588};
auto beg = text.begin();
auto end = text.end();
auto mid = text.begin() + (end - beg) / 2;
int sought = 60555;
while (mid != end && *mid != sought)
{
if (sought < *mid)
{
end = mid;
for (auto it = beg; it != mid; it++)
cout << *it << " ";
}
else
{
beg = mid + 1;
for (auto it = beg; it != end; it++)
cout << *it << " ";
}
mid = beg + (end - beg) / 2;
cout << endl;
}
cout << "position:" <<&mid<< endl;
cout << "search element:"<<*mid << endl;
cin.get();
return 0;
}
#include<vector>
using namespace std;
using std::vector;
int main()
{
vector<int> text{54,87,575,4587,54245,54255,58655,59654,60000,60555,65588};
auto beg = text.begin();
auto end = text.end();
auto mid = text.begin() + (end - beg) / 2;
int sought = 60555;
while (mid != end && *mid != sought)
{
if (sought < *mid)
{
end = mid;
for (auto it = beg; it != mid; it++)
cout << *it << " ";
}
else
{
beg = mid + 1;
for (auto it = beg; it != end; it++)
cout << *it << " ";
}
mid = beg + (end - beg) / 2;
cout << endl;
}
cout << "position:" <<&mid<< endl;
cout << "search element:"<<*mid << endl;
cin.get();
return 0;
}