From bee4d3def5aee74782fcdf36e9a1984ebaa51f9b Mon Sep 17 00:00:00 2001 From: Abir Hasan <98998279+h-abir@users.noreply.github.com> Date: Thu, 1 Jun 2023 11:24:30 +0600 Subject: [PATCH] Create Binary_search.cpp --- Binary_search.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Binary_search.cpp diff --git a/Binary_search.cpp b/Binary_search.cpp new file mode 100644 index 0000000..7403cda --- /dev/null +++ b/Binary_search.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; +int main(){ + int n; + cin>>n; + vector v(n); + for(int i=0; i>v[i]; + } + + int to_find; + cin >> to_find; + int lo = 0, hi = n-1; + int mid; + + while(hi -lo >1){ + mid = (hi+lo)/2; + if(v[mid]