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

左连接的一种实现方式

时间:2016-09-10 16:19:48      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include <Windows.h>

#define row1 4
#define row2 3
#define column1 3
#define column2 3

int main() {
    int x1[row1][column1 + column2 - 1] = {
        {1, 2, 3, 0, 0},
        {2, 3, 4, 0, 0},
        {3, 4, 5, 0, 0},
        {4, 5, 6, 0, 0}
    };

    int x2[row2][column2] = {
        {1, 5, 6},
        {2, 7, 8},
        {4, 9, 10}
    };

    int i = 0;
    int j = 0;

    while (i < row1)
    {
        if (x1[i][0] > x2[j][0])
        {
            j++;
        }
        else if (x1[i][0] < x2[j][0])
        {
            i++;
        }
        else
        {
            for (int k = 1; k < column2; k++)
            {
                x1[i][column1 + k - 1] = x2[j][k];
            }
            i++;
        }
    }

    for (int i = 0; i < row1; i++)
    {
        for (int j = 0; j < column1 + column2 - 1; j++)
        {
            std::cout << x1[i][j] <<  ;
        }
        std::cout << std::endl;
    }

    system("pause");

    return 1;
}

 

左连接的一种实现方式

标签:

原文地址:http://www.cnblogs.com/zjchen/p/5859451.html

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