线性表的交(intersection of linear tables)

线性表的交(intersection of linear tables)

ID:15254947

大小:33.50 KB

页数:10页

时间:2018-08-02

线性表的交(intersection of linear tables)_第1页
线性表的交(intersection of linear tables)_第2页
线性表的交(intersection of linear tables)_第3页
线性表的交(intersection of linear tables)_第4页
线性表的交(intersection of linear tables)_第5页
资源描述:

《线性表的交(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

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。