Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
bin search
//Title of this code //g++ 4.8.2 #include <iostream> #include <vector> int find(std::vector<int>& t, int n) { int begin = 0; int end = t.size() - 1; while (begin <= end) { int mid = (end - begin) / 2 + begin; if (t[mid] == n) { return mid; } else if (t[mid] < n) { begin = mid + 1; } else { end = mid - 1; } } return -1; } int main() { std::vector<int> t = {2,4,6,8,10,11,14,18,23,32}; int i = find(t, 11); std::cout << "t[" << i << "] = " << t[i] << std::endl; }
run
|
edit
|
history
|
help
0
3
Overland pg. 68
Two-phase sample with GCC
series
IceCream
CyclicExpression Checker
Reverse factorial
Triplet sum in array
Zadanie Kalkulator z bajerami
Breakfast Static Function