c语言线性顺序表,C语言程序——线性顺序表.doc

44cb7578e1df5412b94317daaa3307ba.gifC语言程序——线性顺序表.doc

下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。

2.下载的文档,不会出现我们的网址水印。

3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。

文档包含非法信息?点此举报后获取现金奖励!

下载文档到电脑,查找使用更方便

14

积分

还剩页未读,继续阅读

关 键 词:C语言程序线性顺序表

顺序表c语言

顺序表

程序c语言

资源描述:

程序清单:

线性顺序表1:

#define MaxSize 100

typedef char ET;

#include #include #include struct list

{

ET alist[MaxSize];

int size;

};

void Setnull(struct list *p)

{

if(p->alist[0]= =NULL)

exit(1);

else

{

p->alist[0]=NULL;

p->size=0;

}

}

int Length(struct list *p)

{

return strlen(p->alist);

}

ET Get(struct list*p,int i)

{

if(i<0||i>p->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->alist[j]!=NULL;j++)

if(p->alist[j]= =x)break;

return ++j;

}

void Insert(struct list *p,int i,ET x)

{

if(p->size= =MaxSize)

{

printf("the list is full\n");

exit(1);

}

int j;

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;

}

void Delete(struct list *p,int i)

{

if(i<0||i>p->size)

{

printf("the number is wrong!\n");

exit(1);

}

for(;p->alist[i]!=NULL;i++)

p->alist[i-1]=p->alist[i];

p->alist[i-1]=NULL;

p->size=p->size-1;

}

void Display(struct list *p)

{

int i;

for(i=0;p->alist[i+1]!=NULL;i++)

printf("%c->",p->alist[i]);

printf("%c",p->alist[i]);

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 %d\n",p.size);

printf("please enter the elements you want to search:\n");

scanf("%s",&b);

j=Locate(&p,b);

printf("%c's position is:%d\n",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:%c\n",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 400

static int RandArray[MAXSIZE];

void RandomNum()

{

int i;

srand((int)time(NULL));

for(i=0;ialist[j])

{

m=alist[k];

alist[k]=alist[j];

alist[j]=m;

}

}

fclose(f);

for(i=0;ialist[i]= =NULL;中多写了一个等号,将其改为p->alist[i]=NULL;后构建正确。

3. 编译程序,没有出现错误和警告错误。

4. 运行程序,得到正确结果。

线性顺序表2

先仔细观察所写程序在哪些方面有错误,将文本改进后再用计算机调试

1. 构建程序,出现错误,

随机数.cpp

G:\随机数.cpp(16) : error C2065: 'GetTickCount' : undeclared identifier

执行 cl.exe 时出错.

随机数.obj - 1 error(s), 0 warning(s)

发现没有将注明头文件#include "windows.h"和#include "winbase.h"

2.先构建程序,没有错误和警告错误,再编译程序,没有错误和警告错误,运行程序发现随机数排列不整齐,数与数之间没有间隙,分析后将printf("%4d",alist[i]);改为 printf("%6d ",alist[i]);

3. 再次构建程序,没有错误和警告错误,再编译程序,没有错误和警告错误,运行程序得到正确结果。

展开阅读全文

温馨提示:

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。

2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。

3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。

4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。

5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。

6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。

7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

bb6249c6567dd4384e6ab3556cfc22ed.gif 

人人文库网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

关于本文

本文标题:C语言程序——线性顺序表.doc

链接地址:https://www.renrendoc.com/p-17316120.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值