C语言程序——线性顺序表.doc_第1页
C语言程序——线性顺序表.doc_第2页
C语言程序——线性顺序表.doc_第3页
C语言程序——线性顺序表.doc_第4页
C语言程序——线性顺序表.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程序清单:线性顺序表1:#define MaxSize 100typedef char ET;#include #include #include struct listET alistMaxSize;int size;void Setnull(struct list *p)if(p-alist0= =NULL)exit(1);else p-alist0=NULL;p-size=0;int Length(struct list *p)return strlen(p-alist);ET Get(struct list*p,int i)if(ip-size)printf(the number is wrong!n);exit(1);else return (p-alist-i);int Locate(struct list *p,ET x)int j;for(j=0;p-alistj!=NULL;j+)if(p-alistj= =x)break;return +j;void Insert(struct list *p,int i,ET x)if(p-size= =MaxSize)printf(the list is fulln);exit(1); int j; j=p-size; for(;j=(i-1);j-)p-alistj+1=p-alistj;p-alisti-1=x;p-size=p-size+1;void Delete(struct list *p,int i)if(ip-size)printf(the number is wrong!n);exit(1);for(;p-alisti!=NULL;i+)p-alisti-1=p-alisti;p-alisti-1=NULL;p-size=p-size-1;void Display(struct list *p)int i;for(i=0;p-alisti+1!=NULL;i+)printf(%c-,p-alisti);printf(%c,p-alisti);printf(n);void main()int i,j,k,l;ET a,b,c;struct list p;Setnull(&p);printf(please enter the elements:n); scanf(%s,&p.alist);p.size=Length(&p);printf(my list is:n);Display(&p);printf(the length of the list is %dn,p.size);printf(please enter the elements you want to search:n);scanf(%s,&b);j=Locate(&p,b);printf(%cs position is:%dn,b,j);printf(please enter the position you want to search:); scanf(%d,&i);a=Get(&p,i);printf(the element in position %d is:%cn,i,a);printf(please enter the position and the element:);scanf(%d,%c,&k,&c); Insert(&p,k,c);printf(after insert %c,the list is:n,c);Display(&p);printf(please enter the position you want to delete:n);scanf(%d,&l);Delete(&p,l);printf(after delete the element in position %d,the list is:n,l);Display(&p); printf(n);线性顺序表2:#include #include #include #include #include #define MAXSIZE 1000#define N 400static int RandArrayMAXSIZE;void RandomNum() int i; srand(int)time(NULL); for(i=0;iMAXSIZE;i+) RandArrayi=(int)rand()%1000;void main()int alistN,i,j,k;FILE *f; if(f=fopen(SortRes.txt,w)= =NULL)printf(cant open filen);exit(0);RandomNum();for(i=0;iMAXSIZE; i+)fprintf(f,%d,RandArrayi);fclose(f);if(f=fopen(SortRes.txt,r)= =NULL)printf(cant open filen);exit(0); float start=(float)GetTickCount(); fscanf(f,%d,&alist0);for(i=1;iN;i+)int m;fscanf(f,%d,&alisti);for (j=0;j=i;j+)for(k=0;kalistj)m=alistk;alistk=alistj;alistj=m;fclose(f);for(i=0;ialisti= =NULL;中多写了一个等号,将其改为p-alisti=NULL;后构建正确。3 编译程序,没有出现错误和警告错误。4 运行程序,得到正确结果。线性顺序表2先仔细观察所写程序在哪些方面有错误,将文本改进后再用计算机调试1 构建程序,出现错误, 随机数.cppG:随机数.cpp(16) : error C2065: GetTickCount : undeclared identifier执行 cl.exe 时出错.随机数.obj - 1 error(s), 0 warning(s)发现没有将注明头文件#include windows.h和#include winbase.h2先构建程序,没有错误和警告错

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论