2015年大二上-数据结构-顺序表(1)-求集合并集

/* 
*Copyright (c) 2014,烟台大学计算机学院 
*All rights reserved. 
*文件名称:Annpion.cpp 
*作者:王耀鹏 
*完成日期:2015年10月22日 
*版本号:v1.0 
* 
*问题描述:求集合并集。 
*输入描述:2个集合。 
*输出描述:2个集合的并集。 
*/  
#include "list.h"
#include 
void unionList(SqList *LA, SqList *LB, SqList *&LC )
{
    int i,j;
    IniList(LC);
    for(i =0;iLength;++i)
    {
        LC->data[i]=LA->data[i];
    }
    for(j=0;jLength;++j)
    {
        if(!LocateElem(LA,LB->data[j]))
        {
            LC->data[i]=LB->data[j];
            ++i;
        }

    }
    LC->Length=i;
}
int main()
{
    SqList *sq_a, *sq_b, *sq_c;
    ElemType a[6]= {5,8,7,2,4,9};
    CreateList(sq_a, a, 6);
    printf("LA: ");
    DispList(sq_a);

    ElemType b[6]= {2,3,8,6,0};
    CreateList(sq_b, b, 5);
    printf("LB: ");
    DispList(sq_b);
    unionList(sq_a, sq_b, sq_c);
    printf("LC: ");
    DispList(sq_c);
    return 0;
}

运行结果:

2015年大二上-数据结构-顺序表(1)-求集合并集_第1张图片

你可能感兴趣的:(2015年大二上-数据结构-顺序表(1)-求集合并集)