码迷,mamicode.com
首页 > 其他好文 > 详细

将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。

时间:2014-08-15 09:33:27      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:style   color   for   ar   amp   line   size   on   

int a[3] = {12, 15, 17};
    int b[4] = { 2, 8, 16, 22};
    int c[7] = {0};
    int i = 0, j = 0, k = 0;
    while (i < 3 && j < 4 ) {
        if (a[i] > b[j]) {
            c[k++] = b[j++];
        } else {
            c[k++] = a[i++];
        }
    }
    while (i < 3) {
        c[k++] = a[i++];
    }
    while (j < 4) {
        c[k++] = b[j++];
    }
    for (int i = 0; i < 7; i++) {
        printf("%d ", c[i]);
    }

将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。,布布扣,bubuko.com

将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。

标签:style   color   for   ar   amp   line   size   on   

原文地址:http://blog.csdn.net/chenhongyi_1992/article/details/38579813

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!