Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary search2
//Title of this code #include <iostream> #include <vector> using namespace std; template<class T> int bin_search(vector<T> t, T val) { int i = 0; int j = t.size() - 1; while (i != j) { int k = i + (j - i) / 2; cout << i << " - " << k << " - " << j << endl; if (t[k] < val) i = k + 1; else if (t[k] > val) j = k - 1; else return k; } if (t[i] == val) return i; return -1; } int main() { vector<double> t; for (int i = 0; i < 100000; ++i) t.push_back(i*3.2); int p = bin_search<double>(t, 10000); cout << p << " " << t[p]; }
run
|
edit
|
history
|
help
0
Gauss 4x4
reverse linked list
Square of maximum
decode
Lex cpp
Policy based smart pointer
Base conversion
Shortest Non Common Subsequence
NonparaU
1163. Last Substring in Lexicographical Order