数据结构 用c语言写的 集合的并、交和差运算的程序

来源:百度知道 编辑:UC知道 时间:2024/05/30 11:17:22
基本要求:(1)集合的元素限定为小写字母字符〔‘a’..'z'〕.
(2)演示程序以用户和计算机的对话方式执行。
实现提示:
以有序链表表示集合。

以下程序由标准C实现,并经严格测试。程序通过单链表存储集合

#include<stdio.h>
#include<stdlib.h>

typedef struct pointer{
char dat;
struct pointer *link;
} pointer;

void readdata(pointer *head){ //读集合
pointer *p;
char tmp;
printf("input data ('0' for end):");
scanf("%c",&tmp);
while(tmp!='0')
{
if((tmp<'a')||(tmp>'z'))
{
printf("输入错误!必须为小写字母!\n");
return;
}
p=(pointer *)malloc(sizeof(struct pointer));
p->dat=tmp;
p->link=head->link;
head->link=p;
scanf("%c",&tmp);
}
}

void disp(pointer *head){ //显示集合数据
pointer *p;
p=head->link;
while(p!=NULL)
{
printf("%c ",p->dat);
p=p->link;
}
printf("\n");
}

void