From 7248811e71851110dc267f86199d20b6b27a2e35 Mon Sep 17 00:00:00 2001 From: Manav39 <90371681+Manav39@users.noreply.github.com> Date: Sun, 23 Oct 2022 12:13:59 +0530 Subject: [PATCH 1/2] Adding Insertion Sort in C++ --- InsertionSort.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 InsertionSort.cpp diff --git a/InsertionSort.cpp b/InsertionSort.cpp new file mode 100644 index 0000000..9f34f48 --- /dev/null +++ b/InsertionSort.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main() +{ + int a[]={34,12,76,31,21,98}; + cout<<"Array Before Sorting"<=0&&temp<=a[j]) + { + a[j+1]=a[j]; + j--; + } + a[j+1]=temp; + } + cout<<"Array after Sorting"< Date: Sun, 23 Oct 2022 12:15:46 +0530 Subject: [PATCH 2/2] Adding Binary Search in C++ --- binarysearch.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 binarysearch.cpp diff --git a/binarysearch.cpp b/binarysearch.cpp new file mode 100644 index 0000000..f4431b5 --- /dev/null +++ b/binarysearch.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; +int binary_search(int arr[],int key,int n) +{ + int start=0; + int end=n-1; + int mid=(start+end)/2; + while(start<=end) + { + if(arr[mid]==key) + { + return mid; + } + if(key>arr[mid]) + { + start=mid+1; + } + else + { + end=mid-1; + } + mid=(start+end)/2; + } + return -1; +} +int main() +{ + int n,i,j,a[50],temp,key,index; + cout<<"Enter the Number of elements in Array : "; + cin>>n; + cout<<"Enter the value of each element in Array"<>a[i]; + } + for(i=0;ia[j+1]) + { + temp=a[j]; + a[j]=a[j+1]; + a[j+1]=temp; + } + } + } + cout<<"Sorted Array"<>key; + index=binary_search(a,key,n); + cout<<"Element "<