集合 的交并和差的运算与实现.docVIP

  • 6
  • 0
  • 约5.48千字
  • 约 7页
  • 2016-12-25 发布于重庆
  • 举报
#include malloc.h #include stdio.h #include stdlib.h #include conio.h #include iostream.h #include string.h // 顺序表定义 #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define IN_THIS_LIST 1 #define NOT_IN_THIS_LIST 0 //宏定义 typedef char Elemtype; typedef int Status; typedef struct List { Elemtype data; struct List *next; }LNode,*LinkList; //结构体定义 Status InitList(LinkList L) { L=(LinkList)malloc(sizeof(LNode)); if(!L) exit(OVERFLOW); L-data=NULL;L-next=NULL; return OK; } //构造表头 Status PrintList(LinkList L) { LinkList PrintList=L-next; if(!L-next) {cout该集合为空!endl;return ERROR;} while(PrintList-next) { coutPrintList-data,; PrintList=PrintList-next; } coutPrintList-data; coutendl; return OK; } //输出表中元素 Status InsertList(LinkList L,Elemtype e) { if((int)e97||(int)e122) return ERROR; LinkList compare=(LinkList)malloc(sizeof(LNode)); LinkList insertdata=(LinkList)malloc(sizeof(LNode)); compare=L; while(compare-next) { if(e==compare-next-data) return TRUE; else if(e(compare-next-data)) { insertdata-next=compare-next; insertdata-data=e; compare-next=insertdata; return OK; } compare=compare-next; } insertdata-data=e; compare-next=insertdata; insertdata-next=NULL; return OK; } //向表中增加元素 Status DeleteList_data(LinkList L,Elemtype e) { LinkList Deletedata=L-next; while(Deletedata-next) { if(!(Deletedata-next-next)(Deletedata-next-data==e)) {Deletedata-next=NULL; return OK;} if(Deletedata-next-data==e) { Deletedata-next=Deletedata-next-next; return OK; } Deletedata=Deletedata-next; } Deletedata=L-next; if(Deletedata-data==e) { L-next=Deletedata-next; return OK; } return ERROR; } Status jiaoji(LinkList La,LinkList Lb,LinkList L) { LinkList Pa=La-next; LinkList Pb=Lb-next; while(Pa) { while(Pb) { if(Pb-dat

文档评论(0)

1亿VIP精品文档

相关文档