资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言函数单独运行吗 c语言函数单独运行吗

C语言实现数据结构的线性链表,插入和删除函数单独运行的时候都正确,为什么先插入后删除就运行不了?

//我只能说,代码逻辑混乱,特橘棚别是索引,怎么是从1开始的,与一般逻辑不符(从0开始)

我们提供的服务有:成都网站建设、成都做网站、微信公众号开发、网站优化、网站认证、镶黄ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的镶黄网站制作公司

//按照你的意图修改如下,能正常运行了。

#includeiostream

#includestdlib.h

using namespace std;

#define null 0

typedef char ElemType;

typedef struct LNode

{

ElemType data;

struct LNode *next;

} LNode,*LinkList;

int ListLength(LinkList L) {

int n=0;

struct LNode*q=L;

if(L==NULL)

cout"链表为空"endl;

while(q!=NULL)

{

q=q-next;

n++;

}

return n;

}

ElemType GetElem(LinkList L,int i)

{

int j=1;

struct LNode*q=L;

while(jiq!=NULL)

{

q=q-next;

j++;

}

if(q!=NULL)

return (q-data);

else

cout"位置参数不正确"endl;

return 0;

}

void InsertList (LinkList L,ElemType x,int i)

{

int j=1;

struct LNode*q,*s;

s=new LNode;

s-data=x;

q=L;

if(i==1)

{

s-next=q;

L=s;

}

else

{

while(jiq-迅桐next!=NULL)

{

q=q-next;

j++;

}

if(j==i-1)

{

s-next=q-next;

q-next=s;

}

else

cout"位置参数不正确"endl;

}

}

int DeleteElem(LinkList L,int i)

{

int j=1;

struct LNode *q=L,*t;

if(i==1)

{

t=q;

L=q-next;

}

else

{

while(ji-1q-next!=NULL)

{

q=q-next;

j++;

}

if(q-next!=NULLj==i-1)

{

t-next=q-next;

q-next=t;

}

else

cout"位置参数不正圆昌则确"endl;

}

if(t)

delete t;

return 0;

}

void DisplayList(LinkList L)

{

struct LNode*q;

q=L;

cout"链表元素: ";

if(q==NULL)

cout"链表为空"endl;

else

{

while(q!=NULL)

{

coutq-data" ";

q=q-next;

}

}

coutendl;

}

void main()

{

LinkList LA = NULL;

ElemType cs;

int len=0;

InsertList(LA, 'a', 1);

InsertList(LA, 'B', 2);

InsertList(LA, 'C', 3);

cs=GetElem(LA, 3);

len=ListLength(LA);

DisplayList(LA);

}


文章标题:c语言函数单独运行吗 c语言函数单独运行吗
网页路径:http://cdkjz.cn/article/dsphccj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220