From f1b7625be6e18d11b66ae537d8468093e4a008d5 Mon Sep 17 00:00:00 2001 From: HimanshuMishra-prog <54746074+HimanshuMishra-prog@users.noreply.github.com> Date: Tue, 15 Oct 2019 14:31:55 +0530 Subject: [PATCH] Update Binary_Search.cpp --- Binary_Search.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) 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 +}