#include <stdio.h>
void merge(int low,int mid,int high,int array[],int temp[]) { int i=low,j=mid+1,p=0; while(i<=mid&&j<=high) temp[p++]=(array[i]<array[j])?array[i++]:array[j++]; while(i<=mid) temp[p++]=array[i++]; while(j<=high) temp[p++]=array[j++]; for(p=0,i=low;i<=high;i++,p++) { printf("%d<",temp[p]); array[i]=temp[p]; } printf("\n"); } mergeSort(int low,int high,int array[],int temp[]) { int mid; if(low<high) { mid=(low+high)/2; mergeSort(low,mid,array,temp); mergeSort(mid+1,high,array,temp); merge(low,mid,high,array,temp); } }
int main() { int shu[]={23,4,56,12,13,11,19,7,5,6,3,7,32,27}; int n=sizeof(shu)/sizeof(int); int tem[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int i; mergeSort(0,n-1,shu,tem); for(i=0;i<n;i++) { printf("%d<",shu[i]); } return 0; }
|