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
Stream generalization
shell sort
Sorting Array
Korelacja Pearsona lol
Splitwise Problem - 2
constructing object on first use as return value of (pointer to) object-returning function
Patara asoebi
Tray
Dij. Algo
Widget Class with dynamic memory and pointers