The feature of this series of blogs is--give the results of each order
Originally wanted to write a good process, get a picture of what, but think online analysis too much, are better, so these blog even if it is a summary of their own it.
#include <stdio.h> #include <limits.h> #include <malloc.h>int a[10]={2,8,5,7,4,3,1,9,6,10};void Merge (int *m, int x, int y, int z) {int b1,b2,i,j,k;b1=y-x+1;b2=z-y;int *tm1= (int*) malloc (sizeof (int) * (b1+1)); int *tm2= ( int*) malloc (sizeof (int) * (b2+1)); for (i=0;i<b1;i++) tm1[i]=m[i+x];for (j=0;j<b2;j++) tm2[j]=m[j+y+1];tm1[i]= Tm2[j]=int_max;for (k=x,i=0,j=0;k<=z;k++) {if (Tm1[i]<tm2[j]) {m[k]=tm1[i];i++;} else{m[k]=tm2[j];j++;}} Free (TM1); free (TM2);} void mergesort (int *m,int n1, int n2) {if (n1<n2) {int n= (N1+N2)/2; MergeSort (M,n1,n); MergeSort (m,n+1,n2), merge (M,N1,N,N2), for (int t=0;t<10;t++) printf ("%d", m[t]);p rintf ("\ n");}} int main () {int i;for (i=0;i<10;i++) printf ("%d", A[i]);p rintf ("\ n \ n"); MergeSort (a,0,9);p rintf ("\ n final result \ n"), for (i=0;i<10;i++) printf ("%d", A[i]);p rintf ("\ n"); return 0;}
Run results
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/22/wKioL1VAprOB9GM3AAFDjJiDsmw624.jpg "title=" 1.jpg " alt= "Wkiol1vaprob9gm3aafdjjidsmw624.jpg"/>
This article is from the "hacker" blog, make sure to keep this source http://anglecode.blog.51cto.com/5628271/1640427
Sorting algorithm Big Collection _ merge sort _1 (divide and conquer thought)