我刚才编写了一个单链表的函数,如果不调用函数的话我能编写能运行的,但是现在调用了一个函数,就出错了

[复制链接]
查看11 | 回复1 | 2011-10-30 10:11:20 | 显示全部楼层 |阅读模式
#includestdio.h#includemalloc.htypedefstructnode{intdata;structnode*next;}node,*L;voidlistinsert(Lhead,inti,inte)//顺序表的插入函数{node*s,*p;intj;p-data=e;s=head;for(j=1;ji;j)s=s-next;p-next=s-next;s-next=p;}main(){inti,b,c,d;node*s,*head,*pre,*p;head=(node*)malloc(sizeof(node));head-next=head;head-data=0;pre=head;for(i=1;i6;i)//创建顺序表,且第n个数的值为n*n{s=(node*)malloc(sizeof(node));pre-next=s;s-data=i*i;pre=s;}s=head;for(i=1;i6;i)//输出5个数{s=s-next;printf(\"%d\\n\",s-data);}scanf(\"%d,%d\",//输入要插入的数的位置和要插入的数,之间用,隔开listinsert(head,b,c);//调用函数listinserts=head;for(i=1;i6;i){s=s-next;printf(\"%d\\n\",s-data);}}
回复

使用道具 举报

千问 | 2011-10-30 10:11:20 | 显示全部楼层
//listinsert函数的p没有初始化就用了voidlistinsert(Lhead,inti,inte)//顺序表的插入函数{node*s,*p;intj;p=(node*)malloc(sizeof(node));//p要初始化的p-data=e;s=head;for(j=1;ji;j)s=s-next;p-next=s-next;s-next=p;}来自:求助得到的回答
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行