集合的交并差运算实例

来源:百度知道 编辑:UC知道 时间:2024/07/12 10:56:56
以链表存储集合,在此基础上完成对集合的操作。
要求设计类(或类模板)来描述集合,包含必要的构造函数和析构函数,以及其他能够完成如下功能的成员函数:
 输入、输出集合
 查询集合中的元素
 在集合中进行插入、删除元素
 实现集合的并、交、差运算
并设计主函数测试该类。

#include<malloc.h> // malloc()等
#include<stdio.h> // EOF(=^Z或F6),NULL
#include<stdlib.h> // atoi()
#include<math.h> // floor(),ceil(),abs()
#include<process.h> // exit()

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

typedef int Status;
//**************线性表的动态分配顺序存储结构*********************
typedef struct
{
int num;
char name[20];
float score;
}ElemType;
typedef struct
{
ElemType * elem;
int length;
int listsize;
}SqList;

//***************线性表的初始化********************************
Status InitList_Sq(SqList &L)
{
L.elem=(ElemType *)malloc(LIST_INIT_SIZE *sizeof(ElemType));
if(!L.elem)
exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}//InitLis