Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int binarySearch(int l,int r,int x){
- if(r>=l){
- int mid = l+(r-l)/2;
- if(vect[mid] == x)
- return mid;
- if(vect[mid] > x)
- return binarySearch(l,mid-1,x);
- if(vect[mid]<x){
- return binarySearch(mid+1,r,x);
- }
- }
- return -1;
- }
- int main(){
- /*
- //pb1
- drumSpreCasa(3);
- cout<<"Ai ajuns acasa";
- */
- if(binarySearch(0,6,5) == -1){
- cout<<"Numarul nu se afla in vector";
- }
- else
- {
- cout<<"Exista";
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement