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
SL_Dictance challange
0-1 Knapsack
string_match
Certificate Printing
temp_new
union of two sorted array
binary
alma
Bin Tree playground
BinTraversal v2