1#include <iostream>2 using namespacestd;3 intMerge (intA[],intPintQintR);4 intMerge_sort (intA[],intPintR);5 intOutPut (intA[],intn);6 intMain ()7 {8 inta[]={2,3,5,4,1,6};9Merge_sort (A,1,6);TenOutPut (A,6); One return 0; A } - - intMerge (intA[],intPintQintR) the { - intn1=q-p+1; - intn2=r-Q; - int* l=New int[N1]; + int* r=New int[N2]; - for(intI=0; i<n1;i++) + { Al[i]=a[p+i-1]; at } - for(intI=0; i<n2;i++) - { -r[i]=a[q+i]; - } - for(intI=0, j=0, k=p-1; k<r;k++) in { - if(l[i]<=r[j]&&i<n1| | j==n2) to { +a[k]=L[i]; -i++; the } * Else $ {Panax Notoginsenga[k]=R[j]; -J + +; the } + } A delete []l; the delete []r; + return 0; - } $ $ intMerge_sort (intA[],intPintR) - { - if(p<R) the { - intq= (P+R)/2;Wuyi Merge_sort (a,p,q); theMerge_sort (a,q+1, R); - Merge (a,p,q,r); Wu } - return 0; About } $ - intOutPut (intA[],intN) - { - for(intI=0; i<n;i++) A { +cout<<a[i]<<'\ n'; the } - return 0; $}
Cock Silk needs to be reversed learn C + + and algorithm------Merge sort