归并排序
[ 本帖最后由 longwu9t 于 2015-4-2 16:16 编辑 ]
程序代码:
#include <stdio.h> #define LENX 7 #define LENY 9 #define LEN (LENX + LENY) int main(void) { int i, a[LEN] = {0}, x[LENX] = {0}, y[LENY] = {0}; int *pa = a, *px = x, *py = y; for(i = 0; i < LENX; i++) printf("%-2d%s", (x[i] = (i + 1) * 3), i < LENX - 1 ? " " : "\n"); for(i = 0; i < LENY; i++) printf("%-2d%s", (y[i] = (i + 1) * 2), i < LENY - 1 ? " " : "\n"); for(; px < x + LENX && py < y + LENY;) *pa++ = (*px < *py) ? *px++ : *py++; if(px == x + LENX) while(py < y + LENY) *pa++ = *py++; else while(px < x + LENX) *pa++ = *px++; for(i = 0; i < LEN; i++) printf("%-2d%s", a[i], i < LEN - 1 ? " " : "\n"); return 0; }
[ 本帖最后由 longwu9t 于 2015-4-2 16:16 编辑 ]
Only the Code Tells the Truth K.I.S.S