From c349d1eb6c140dd5a2a2d87478fc08f41baba1ae Mon Sep 17 00:00:00 2001 From: SHARIF NAWAZ Date: Tue, 1 Oct 2019 09:38:56 +0530 Subject: [PATCH] Create mergesort This is merge sort prgram in c++. --- sorting/mergesort | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 sorting/mergesort diff --git a/sorting/mergesort b/sorting/mergesort new file mode 100644 index 0000000..0fd72ba --- /dev/null +++ b/sorting/mergesort @@ -0,0 +1,85 @@ +#include +#include +void do_merge(int a[],int,int); +void do_sorting(int a[],int,int,int); +using namespace std; +int main() +{ + int n,i; + cout<<"Enter number of elements\n"; + cin>>n; + int *a=(int *)malloc(n*sizeof(int)); + cout<<"Enter elements\n"; + for(int l=0;l>a[l]; + } + do_merge(a,0,n-1); + cout<<"Sorted list is given below\n"; + for(int l=0;la[j]) + { + temp[c]=a[j]; + j++; + c++; + } + else + { + temp[c]=a[i]; + i++; + c++; + } + + } + while(i<=m) + { + temp[c]=a[i]; + i++; + c++; + } + while(j<=e) + { + temp[c]=a[j]; + j++; + c++; + } + int k=0; + for(int l=s;l<=e;l++) + { + a[l]=temp[k++]; + + } + +} + +