fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int s=0;
  4. int bin(int value,int arr[],int left,int right)
  5. {
  6.  
  7. if(left>s||right>s)
  8. return -1;
  9.  
  10. int temp=(left+right)/2;
  11.  
  12.  
  13.  
  14. if(arr[temp]>=value&&(temp==0||arr[temp-1]<value))
  15. return temp;
  16.  
  17. else if(arr[temp]>=value)
  18. {
  19. bin(value,arr,left,temp);
  20. }
  21. else
  22. {
  23. bin(value,arr,temp+1,right);
  24. }
  25.  
  26. }
  27.  
  28.  
  29. int main() {
  30. int arr[10]={1,2,3,4,5,6,7,10,14,20};
  31. s=9;
  32. int val=bin(2,arr,0,9);
  33. cout<<val<<endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 15224KB
stdin
Standard input is empty
stdout
1