diff --git a/C++/Binary Search.cpp b/C++/Binary Search.cpp index 825b321..9082b98 100644 --- a/C++/Binary Search.cpp +++ b/C++/Binary Search.cpp @@ -1,36 +1,33 @@ -int binarySearch(int arr[], int l, int r, int x) -{ - while (l <= r) { - int m = l + (r - l) / 2; - - // Check if x is present at mid - if (arr[m] == x) - return m; - - // If x greater, ignore left half - if (arr[m] < x) - l = m + 1; - - // If x is smaller, ignore right half +int binarySearch(int arr[],int size,int element){ + int low,mid,high; + low = 0; + high = size-1; + + while(low<=high){ + mid = (low + high)/2; + if (arr[mid] == element) + { + cout<<"OK\n"; + cout<<"The element "< +//The reason why you don't see drastic changes is the code is same but you could've used {}braces to format which is a good practice and increases readability using namespace std; -int main() -{ - int L; - cin>>L; - int N; - cin>>N; - while(N--) + +int main(){ + int i,j; + cout<<"i"; + cin>>i; + cout<<"j"; + cin>>j; + cout<>W>>H; - if(WL&&H>L||W>L&&H==L||W==L&&H>L) - { if(W!=H) - cout<<"CROP IT"<>a; + cout<<"b"; + cin>>b; + if (ai&&b>i||a>i&&b==i||a==i&&b>i){ + if (a!=b) + { + cout<<"CROP IT"<