資源描述:
《線性表的交(intersection of linear tables)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
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));/*動(dòng)態(tài)分布一個(gè)空間*///if(!l->elem)exit(overflow);l->length=0;/*當(dāng)前線性表元素的個(gè)數(shù)*/l->listsize=list_init_初始存儲(chǔ)容量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個(gè)數(shù)據(jù)元素的值{/*and*/if(i<0
4、
5、>l.length)returnflase;*=l.elem[-1].returnture;}statuslocateelem(sqlistl,int,andstatus(*!)(elemtype,elemtype)){//在順序表中l(wèi),查找第一個(gè)值與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()函數(shù)if(a==and)return1;elsereturn0;}statuslistinsert(sqlist*l,inti,elemtypeand)在線性表的第i個(gè)位子插入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