【问题描述】
编制一个能演示执行集合的并、交和差运算的程序
【基本要求】
(1)集合的元素限定为小写字母字符[ 'a'......'z' ]
(2 )演示程序以用户和计算机对话的方式执行
【测试数据】
【实现提示】
以有序链表表示集合
【代码过程】
1。先定义 集合的数据类型 notes.h
//
notes.h
typedef
struct
LNode
{
ElemType data;
LNode *next;
}
*
Link,
*
Position;

typedef
struct
{
Link head,tail;
int len;
}
LinkSet;
//~
2。以后要用的一些常量放在 constValues.h
#include
<
stdio.h
>
#include
<
malloc.h
>
#include
<
stdlib.h
>
//
函数结果状态代码
#define
TRUE 1
#define
FALSE 0
#define
OK 1
#define
ERROR 0
#define
INFEASIBLE -1
#define
OVERFLOW -2

#define
ElemType int
//
存放数据的类型

typedef
int
Status;
//
函数的返回值
//~
3。集合实现函数 setsFun.h
/****************** 函数定义 *********************/
Status InitSets(LinkSet
&
ls)
{
//初始化 集合
ls.head = (Link) malloc( sizeof(Link));
ls.tail = (Link) malloc( sizeof(Link));
if(!ls.head || !ls.tail) exit(OVERFLOW); //如果分配失败

ls.head->next = ls.tail->next = NULL; //头、尾指针为空
ls.len = 0; //长度为0
return OK;
}

Status CreateNode(Link
&
link,ElemType e)
{
//创建一节点,内容为e
link = (Link) malloc( sizeof(Link));
if(!link) exit(OVERFLOW);
link->data = e; //值设定
link->next = NULL; //指向空
return OK;
}

Position PriorInsertNode(LinkSet
&
ls,Link
&
link)
{
//找出节点link要插入到ls的前一个节点
if(!ls.head->next) return ls.head;
Link h1 = ls.head->next, h2 = h1->next; //h1:前一节点,h2:前一节点的后一节点
if(link->data < h1->data) return ls.head; //如果比第一个节点小,返回头指针
while(h1 && h2){
if(h1->data < (link->data) && h2->data > (link->data) ) //如果>h1 && <h2,说明找到插入的地方了
break;
if(h1->data == (link->data) || h2->data ==(link->data) )
return NULL; //如果重复,返回NULL
编制一个能演示执行集合的并、交和差运算的程序
【基本要求】
(1)集合的元素限定为小写字母字符[ 'a'......'z' ]
(2 )演示程序以用户和计算机对话的方式执行
【测试数据】
【实现提示】
以有序链表表示集合
【代码过程】
1。先定义 集合的数据类型 notes.h










//~
2。以后要用的一些常量放在 constValues.h














//~
3。集合实现函数 setsFun.h































