问题代码:
/*
copyright (t) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:oo.cpp
*作者:肖博文
*完成日期:2016年9月22日
*版本号:v1.0
*问题描述:假设有两个集合 A 和 B 分别用两个线性表 LA 和 LB 表示,即线性表中的数据元素即为集合中的成员。设计算法,用函数unionList(List LA, List LB, List &LC )函数实现该算法,求一个新的集合C=A∪B,即将两个集合的并集放在线性表LC中。
*输入描述:无
*程序输出:无
*/
//注:运用之前建好的算法库,结合对此题算法的进一步分析,程序如下:
//list.h:
#define Maxsize 100
typedef int Elemtype; //自定义数据类型
typedef struct list
{
Elemtype data[Maxsize]; //存顺序表元素
int length; //存顺序表长度
} Sqlist;
void CreateList(Sqlist *&l,Elemtype a[],int n); //由a中的n个元素建立顺序表
void DispList(Sqlist *l); //输出线性表
int ListLength(Sqlist *l); //求顺序表长度
bool GetElem(Sqlist *l,int i,Elemtype &e);
第三周项目3 求集合并集
最新推荐文章于 2023-04-05 17:37:41 发布