第三周项目三 求集合并集
来源:互联网 发布:金税盘数据更新失败 编辑:程序博客网 时间:2024/06/02 04:36
假设有两个集合 A 和 B 分别用两个线性表 LA 和 LB 表示,即线性表中的数据元素即为集合中的成员。设计算法,用函数unionList(List LA, List LB, List &LC )函数实现该算法,求一个新的集合C=A∪B,即将两个集合的并集放在线性表LC中。
提示:
(1)除了实现unnionList函数外,还需要在main函数中设计代码,调用unionList进行测试和演示;
(2)可以充分利用前面建好的算法库[点击…],在程序头部直接加#include<list.h>
即可(工程中最普遍的方法,建议采纳);(3)也可以将实现算法中需要的线性表的基本运算对应的函数,与自己设计的所有程序放在同一个文件中。
解答:
#include "list.h"#include <stdio.h>void unionList(SqList *LA, SqList *LB, SqList *&LC){ int lena,i; ElemType e; InitList(LC); for (i=1; i<=ListLength(LA); i++) //将LA的所有元素插入到Lc中 { GetElem(LA,i,e); ListInsert(LC,i,e); } lena=ListLength(LA); //求线性表LA的长度 for (i=1; i<=ListLength(LB); i++) { GetElem(LB,i,e); //取LB中第i个数据元素赋给e if (!LocateElem(LA,e)) //LA中不存在和e相同者,插入到LC中 ListInsert(LC,++lena,e); }}//用main写测试代码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;}
阅读全文
0 0
- 第三周项目三求集合并集
- 第三周 项目三--求集合并集
- 第三周项目三 求集合并集
- 第三周项目三 求集合并集
- 第三周 项目三 求集合并集。
- 第三周项目三—求集合并集
- 第三周 项目三-【求集合并集】
- 第三周项目三 求集合并集
- 第三周项目三--求集合并集
- 第三周 项目三-求集合并集
- 第三周【项目三-求集合并集】
- 第三周项目三 求集合并集
- 第三周 项目三——求集合并集
- 第三周项目三 求集合并集
- 第三周项目三-求集合并集
- 第三周-项目三求集合并集
- 第三周 项目三 -求集合并集
- 第三周项目三求集合并集
- Powershell最佳安全实践
- 解决 cmd 窗口 php 输出中文乱码问题
- 怎么让图片平铺 传进来的图片自适应这个div
- Java开发代码规范之编程规约(二)——常量定义
- C# 类的继承和Interface接口
- 第三周项目三 求集合并集
- Linux ALSA声卡驱动之八:ASoC架构中的Platform
- bootstrapValidator 根据条件在js中添加或移除校验
- Maven工程pom.xml
- eclipse 常用的15个开发快捷键技巧和快捷键大全
- CFO们也要学习AI吗?
- 扎克伯格订了个小目标:让10亿人用上VR
- 第七周项目二—建立链队算法库
- 备忘信息