資源描述:
《線性表的交(the linear table)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、線性表的交(Thelineartable)#includes"stdio.h"#includes"malloc.h"#definelist_init_size100#definelistincrement10#defineokay1#definespecific1#defineflase0#defineerror-1#defineoverflow-2typedefintstatus;typedefintelemtype;typedefstruct{elemtype*elem.intlength;intlistsize;}sqlist,*psqlist;statusinitli
2、st(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;thelistsize->=0;returnok;}statuslistleng
3、th(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()的元素的位序;elemtype*p;inti=1;p=l.elem;while(i<=l.length&&!as*(
6、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)returnerror;elseif(->->>=thelengthlistsize){newbase=(elemtype*)r
9、ealloc(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,elemtype*){elemtype*p*q;q=&(1->elem[-1]).*=l->elem[-1].p=&(1->elem[l->length-
10、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,d,equal))listinsert(&,the_+l+s).}//returnok;}voiddeal(sqlist,sqlist&lb){intthe_l,lb
11、_l;the_l=listlength(the);lb_l=listlength(lb).intp=lb_l;inti,j,s,t,and.int*p*q;為(i=0;i<=la_l;i++){GetElem(LA,我和S);為(J=0;J<=lb_l;j++){GetElem(LB,J,T);/*(如果){listdelel(和LB,J,E);printf(“%d”,E);}/*如果(locateelem(LB,S,等)){q=s;P=&(LA。元素[拉。length-1]);為(;P>=Q;++q)