#include <iostream>
#define MAXSIZE 100
using namespace std;
typedef struct SqList
{
    int *data;
    int length;
} SqList;
void Input(SqList &L)
{
    int m, i;
    cout << "请输入有序集合元素的个数:" << endl;
    cin >> m;
    for (i = 1; i <= m; i++)
    {
        cout << "请输入第【" << i << "】个元素:";
        cin >> L.data[i - 1];
        L.length++;
    }
}
void MergeList(SqList La, SqList Lb)
{
    SqList Lc;
    Lc.data = new int[MAXSIZE];
    Lc.length = La.length + Lb.length;
    int *pa, *pb, *pc;
    pa = La.data;
    pb = Lb.data;
    pc = Lc.data;
    int i = 1, j = 1;
    while (i <= La.length && j <= Lb.length)
    {
        if (*pa <= *pb)
        {
            *pc++ = *pa++;
            i++;
        }
        else
        {
            *pc++ = *pb++;
            j++;
        }
    }
    while (i <= La.length)
    {
        *pc++ = *pa++;
        i++;
    }
    while (j <= Lb.length)
    {
        *pc++ = *pb++;
        j++;
    }
    cout << "合并后的集合:" << endl;
    for (i = 0; i < Lc.length; i++)
        cout << Lc.data[i] << endl;
}
int main()
{
    while (1)
    {
        int F;
        SqList La, Lb;
        La.data = new int[MAXSIZE];
        La.length = 0;
        Lb.data = new int[MAXSIZE];
        Lb.length = 0;
        cout << "请输入集合A中元素的个数" << endl;
        Input(La);
        cout << endl
             << endl;
        cout << "请输入集合B中元素的个数" << endl;
        Input(Lb);
        MergeList(La, Lb);
        cout << "\t\t\t按【0】退出" << endl;
        cout << "\t\t\t按【1】继续" << endl;
        cin >> F;
        if (F == 0)
            break;
        if (F == 1)
            continue;
    }
    return 0;
}