Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BinSearch
//g++ 7.4.0 #include <iostream> using namespace std; template<class T> int search(T [] , T, int, int); template <class T> int search (T a[], T key, int first, int last) { while (first <= last) { int mid=(first +last)/2; if (key<a[mid]) last = mid -1; else if (key > a[mid]) first =mid +1; else return mid; } return -1; } string s[]= { "Abra","Ka", "Debra", "Zebra", "Libra"}; int main () { string s1; while (cin>>s1){ int location = search(s, s1,0,9); if(location ==-1) cout <<s1<<" is not on the list.\n"; else cout <<s1<< " is in position "<<location <<".\n"; } return 0; }
run
|
edit
|
history
|
help
0
Median of two sorted arrays
Heap sort baaaad
F-Random Strings
random
is_num_palindrom
Eratosfen conmment
Prime Factor
UB mutex lock
nani
is_sorted_30-Seconds-of-C++