From 581efac0f9837e7ba650801e10570d81bf5940ad Mon Sep 17 00:00:00 2001 From: Preethirkrish <44403571+Preethirkrish@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:41:01 +0530 Subject: [PATCH 1/2] program for binary search added --- BINARYSE.CPP | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 BINARYSE.CPP diff --git a/BINARYSE.CPP b/BINARYSE.CPP new file mode 100644 index 0000000..64ed875 --- /dev/null +++ b/BINARYSE.CPP @@ -0,0 +1,42 @@ +#include +#include +void main() +{ clrscr(); + int n,item,a[21], flag=1,first,last,middle; + cout<<"\nEnter no.of elements:"; + cin>>n; + cout<<"\nEnter the elements:"; + for(int i=0;i>a[i]; + } + cout<<"\nenter element to be searched:"; + cin>>item; + first=0; + last=n-1; + middle=(first+last)/2; + while(first<=last) + { + if(a[middle] Date: Wed, 23 Oct 2019 12:14:34 +0530 Subject: [PATCH 2/2] added linear search in c++ --- LINEARSE.CPP | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 LINEARSE.CPP diff --git a/LINEARSE.CPP b/LINEARSE.CPP new file mode 100644 index 0000000..fd8c915 --- /dev/null +++ b/LINEARSE.CPP @@ -0,0 +1,30 @@ +#include +#include +void main() +{ + clrscr(); + int a[11],n,i,k,flag=0; + cout<<"\nEnter the no.of elements:"; + cin>>n; + cout<<"\nEnter the elements:"; + for(i=0;i>a[i]; + } + cout<<"\nEnter the element to be searched:"; + cin>>k; + for(i=0;i