SHARE
TWEET

Untitled

a guest Feb 27th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int binarySearch(int l,int r,int x){
  2.     if(r>=l){
  3.         int mid = l+(r-l)/2;
  4.         if(vect[mid] == x)
  5.             return mid;
  6.         if(vect[mid] > x)
  7.             return binarySearch(l,mid-1,x);
  8.         if(vect[mid]<x){
  9.             return binarySearch(mid+1,r,x);
  10.         }
  11.     }
  12.     return -1;
  13. }
  14.  
  15. int main(){
  16.     /*
  17.     //pb1
  18.     drumSpreCasa(3);
  19.     cout<<"Ai ajuns acasa";
  20.     */
  21.     if(binarySearch(0,6,5) == -1){
  22.         cout<<"Numarul nu se afla in vector";
  23.  
  24.     }
  25.     else
  26.     {
  27.         cout<<"Exista";
  28.     }
  29.     system("pause");
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top