fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int binsearch(int array[], int size, int key){
  5. int left = 0;
  6. int right = size;
  7. int mid;
  8.  
  9. while (left <= right){
  10. mid = left + (right - left) / 2;
  11. if(key < array[mid])
  12. right = mid - 1;
  13. else if(key > array[mid])
  14. left = mid + 1;
  15. else return mid;
  16. }
  17. return -1;
  18. }
  19.  
  20. int main() {
  21. // your code goes here
  22. return 0;
  23. }
Success #stdin #stdout 0s 3092KB
stdin
Standard input is empty
stdout
Standard output is empty