资源描述:
《线性表的交(intersection of linear tables)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、线性表的交(Intersectionoflineartables)#includes"stdio.h"#includes"malloc.h"#definelist_init_size100#definelistincrement10#defineokay1#definespecific1#defineflase0#defineerror-1#defineoverflow-2typedefintstatus;typedefintelemtype;typedefstruct{elemtype*elem.intlength;intlistsize;}sqli
2、st,*psqlist;statusinitlist(sqlist*l)制空表{/**/l->elem=(elemtype*)malloc(10*sizeof(elemtype));/*动态分布一个空间*///if(!l->elem)exit(overflow);l->length=0;/*当前线性表元素的个数*/l->listsize=list_init_初始存储容量size;/**/returnok;}statusdestroylist(sqlist*l)销毁线性表{/**/free(l);l->elem=null;l->length=0;thel
3、istsize->=0;returnok;}statuslistlength(sqlistl){returnl.length;}statusgetelem(sqlistl,inti,elemtype*)用e返回l的第i个数据元素的值{/*and*/if(i<0
4、
5、>l.length)returnflase;*=l.elem[-1].returnture;}statuslocateelem(sqlistl,int,andstatus(*!)(elemtype,elemtype)){//在顺序表中l,查找第一个值与e满足compre()的元素的位序;ele
6、mtype*p;inti=1;p=l.elem;while(i<=l.length&&!as*(p++))++i;if(<=l.length)returni;elsereturn0;}statusequal(elemtype,elemtypeand){//定义equal()函数if(a==and)return1;elsereturn0;}statuslistinsert(sqlist*l,inti,elemtypeand)在线性表的第i个位子插入e{/*and*/elemtype*newbase,*p,*q;if(i<0
7、
8、>l>length)retu
9、rnerror;elseif(->->>=thelengthlistsize){newbase=(elemtype*)realloc(l->elem(l->listsize+listincrement)*sizeof(elemtype));/*if(!newbase)exit(2);*/}q=&(1->elem[-1]).*q=and.p=&(1->elem[l->length-1]).for(;p>=q;p)*(p+1)=*p;+++++++l->length;returnok;}statuslistdelel(sqlist*l,inti,elemt
10、ype*){elemtype*p*q;q=&(1->elem[-1]).*=l->elem[-1].p=&(1->elem[l->length-1]).for(;p>=q;++q)(q-1)=*q;-(1->length).returnok;}///(表的合并...voidunited(sqlist&,sqlistlb){intthe_l,lb_l;inti,s;the_l=listlength(the);lb_l=listlength(lb).for(i=1,the<=lb_l;i++){getelem(lb,&s);if(!locateelem(a
11、,d,equal))listinsert(&,the_+l+s).}//returnok;}voiddeal(sqlist,sqlist&lb){intthe_l,lb_l;the_l=listlength(the);lb_l=listlength(lb).intp=lb_l;inti,j,s,t,and.int*p*q;for(i=0;i<=_l;i++){getelem(,,&d);for(j=0,j<=lb_l;j++){getelem(lb,j.,&t)./*if(s=t){listdelel(&lb,j.,&c).printf("%d",);
12、}*/if(locateelem(lb,s.,equal)){q=&s;p=&(la.elem