12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
-
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int findByName(const vector<int>& humans, const int& name, int min, int max)
- {
- int index = (min + max) / 2;
- if (min > max) {
- return 404;
- }
- else if (humans[index] == name)
- return index;
- else if (humans[index] > name)
- return findByName(humans, name, min, index - 1);
- else
- return findByName(humans, name, index + 1, max);
- }
- int main()
- {
- vector <int> vec;
- vec.push_back(11);
- vec.push_back(9);
- vec.push_back(7);
- vec.push_back(5);
- vec.push_back(3);
- vec.push_back(1);
- cout << vec[0] << endl << findByName;
- }
|