c语言程序——线性顺序表

c语言程序——线性顺序表

ID:8973619

大小:112.50 KB

页数:7页

时间:2018-04-13

c语言程序——线性顺序表_第1页
c语言程序——线性顺序表_第2页
c语言程序——线性顺序表_第3页
c语言程序——线性顺序表_第4页
c语言程序——线性顺序表_第5页
资源描述:

《c语言程序——线性顺序表》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、程序清单:线性顺序表1:#defineMaxSize100typedefcharET;#include#include#includestructlist{ETalist[MaxSize];intsize;};voidSetnull(structlist*p){if(p->alist[0]==NULL)exit(1);else{p->alist[0]=NULL;p->size=0;}}intLength(structlist*p){returnstrlen(p->a

2、list);}ETGet(structlist*p,inti){if(i<0

3、

4、i>p->size){printf("thenumberiswrong!");exit(1);}elsereturn(p->alist[--i]);}intLocate(structlist*p,ETx){intj;for(j=0;p->alist[j]!=NULL;j++)if(p->alist[j]==x)break;return++j;}voidInsert(structlist*p,inti,ETx){if(p->size==Max

5、Size){printf("thelistisfull");exit(1);}intj;j=p->size;for(;j>=(i-1);j--)p->alist[j+1]=p->alist[j];p->alist[i-1]=x;p->size=p->size+1;}voidDelete(structlist*p,inti){if(i<0

6、

7、i>p->size){printf("thenumberiswrong!");exit(1);}for(;p->alist[i]!=NULL;i++)p->alist[i-1]=

8、p->alist[i];p->alist[i-1]=NULL;p->size=p->size-1;}voidDisplay(structlist*p){inti;for(i=0;p->alist[i+1]!=NULL;i++)printf("%c->",p->alist[i]);printf("%c",p->alist[i]);printf("");}voidmain(){inti,j,k,l;ETa,b,c;structlistp;Setnull(&p);printf("pleaseentertheelements:

9、");scanf("%s",&p.alist);p.size=Length(&p);printf("mylistis:");Display(&p);printf("thelengthofthelistis%d",p.size);printf("pleaseentertheelementsyouwanttosearch:");scanf("%s",&b);j=Locate(&p,b);printf("%c'spositionis:%d",b,j);printf("pleaseenterthepositio

10、nyouwanttosearch:");scanf("%d",&i);a=Get(&p,i);printf("theelementinposition%dis:%c",i,a);printf("pleaseenterthepositionandtheelement:");scanf("%d,%c",&k,&c);Insert(&p,k,c);printf("afterinsert%c,thelistis:",c);Display(&p);printf("pleaseenterthepositionyouwantto

11、delete:");scanf("%d",&l);Delete(&p,l);printf("afterdeletetheelementinposition%d,thelistis:",l);Display(&p);printf("");}线性顺序表2:#include#include#include#include#include#defineMAXSIZE1000#defineN400staticintRandA

12、rray[MAXSIZE];voidRandomNum(){inti;srand((int)time(NULL));for(i=0;i

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

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

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