weixin_45490561
weixin_45490561
2019-11-05 22:45
采纳率: 68.4%
浏览 197

为什么这个程序运行后输出链表时出现如图所示的问题?

图片说明
#include
#include
typedef struct splist
{
int data;
splist next;
} splist;
splist *CJ(splist *L)
{
L=(splist
)malloc(sizeof(splist));
L->next=NULL;
splist p;
int n;
int i;
printf("请输入建表的长度");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p=(splist
)malloc(sizeof(splist));
printf("请输入数据");
scanf("%d",p->data);
p->next=L->next;
L->next=p;
}
return (splist*)L;
}
int print(splist *L){
splist *s=L->next;
while(s != NULL){
printf("%d ",s->data);
s = s->next;
}
return 0;
}

int main()
{
splist L=(splist)malloc(sizeof(splist));
L=CJ(L);
print(L);
return 0;
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dabocaiqq
    dabocaiqq 2019-11-06 09:45
    已采纳
    点赞 评论

相关推荐