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"< +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 "<