diff --git a/Binary_Search.cpp b/Binary_Search.cpp index 3c51121..6dd63c9 100644 --- a/Binary_Search.cpp +++ b/Binary_Search.cpp @@ -2,24 +2,9 @@ #include #include using namespace std; - -int main() { - int n,s,i,low,high,mid; - cout<<"Enter the number of elements"; - cin>>n; - - int A[n]; - cout<<"Enter the elements of array"; - for(i=0;i>A[i]; - } - - cout<<"Enter the element to be searched"; - cin>>s; - - sort(A,A+n); //Binary search is applicable only on sorted array - low=0; +void binsearch(int *A,int s){ + int mid; + low=0; high=n-1; //Initially our search space is the whole array while(low<=high) { @@ -39,3 +24,22 @@ int main() { return 0; } + +int main() { + int n,s,i,low,high,mid; + cout<<"Enter the number of elements"; + cin>>n; + + int A[n]; + cout<<"Enter the elements of array"; + for(i=0;i>A[i]; + } + + cout<<"Enter the element to be searched"; + cin>>s; + + sort(A,A+n); + binsearch(A,s);//Binary search is applicable only on sorted array +}