Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement