code:
#include<iostream> #include<vector> #include<map> using namespace std; void Merge(int* a,int l,int m,int r) { int b[11],c[11]; int i,j,lb,lc,tb,tc; lb = m - l + 1; lc = r - m; for(j = 0;j < lb;j++) b[j] = a[j+l]; b[j] = 2147483647; for(j = 0;j < lc;j++) c[j] = a[m+1+j]; c[j] = 2147483647; tb = tc = 0; for(i = l;i <= r;i ++) { if(b[tb] <= c[tc]){ a[i] = b[tb]; tb ++; } else if(b[tb] >c[tc]){ a[i] = c[tc]; tc ++; } } } void Merge_Sort(int* a,int l,int r) { if(l < r){ int m = (l + r)/2; Merge_Sort(a,l,m); Merge_Sort(a,m+1,r); Merge(a,l,m,r); } } int main(void) { int a[10],i; int a_end,a_begin; a_begin = 0; a_end = 9; for(i = 0;i < 10;i ++) cin >> a[i]; Merge_Sort(a,a_begin,a_end); for(i = 0;i <= a_end;i ++) cout << a[i] << " "; cout << endl; return 0; }