#include <stdio.h> #include <string.h> int a[9] = {0,49,38,65,97,76,13,27}; int b[9]; void merge(int s, int m, int t) { int i, j, k; k = s; for (i = s, j = m+1; i <= m && j <= t; ) { if (a[i] < a[j]) { b[k++] = a[i++]; } else { b[k++] = a[j++]; } } for (; i <= m; i++) { b[k++] = a[i]; } for (; j <= t; j++) { b[k++] = a[j]; } for (i = s; i <= t; i++) { a[i] = b[i]; } } void merge_sort(int s, int t) { int m, i; printf("sort (%d, %d)\n", s, t); if (s < t) { m = (s+t) / 2; merge_sort(s, m); merge_sort(m+1, t); merge(s, m, t); } } int main() { int i; merge_sort(1, 7); for (i = 1; i <= 7; i++) { printf("%d ", a[i]); } printf("\n"); getchar(); return 0; }