C语言写链表的问题

tankey0909 tankey0909 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

typedef struct
{
int data;
struct Node *next;



}Node;
typedef Node * LinkList;


LinkList creatLinkList_2()
{
LinkList pRear,pHead,pCur;
int num;

printf("creating pHead...\n");
if( ( pHead = (LinkList)malloc(sizeof(Node)) ) == NULL)
{
printf("failed to allocate memery for pHead");


}
else
{
printf("successfully create pHead!\n");

}
pHead->next = NULL;
pRear = pHead;

while(1)
{
printf("input the number of linklist you want to create:");
printf("(-1 as end )\n");
scanf("%d\n",&num);

if(num == -1)

{
printf("finish creating linklist!");
break;
}

pCur = (LinkList)malloc(sizeof(Node));

pCur->data = num;
pRear->next = pCur;
pRear = pCur;

printf("%n");

}
pRear->next = NULL;

return pHead;



}
void printLinkList(LinkList pHead)
{
LinkList p = pHead;
while(p)
{

printf("your linklist is:\n", p->next->data);
p = p->next;
}
}

#include <stdio.h>
//#include "LinkList.h"
int main()
{
/* LinkList *L = (LinkList *)malloc(sizeof(LinkList));
create_LinkList(&L,5);
LinkList p = *L;
show_LinkList(p,5);
free(L);*/


LinkList pMyList = creatLinkList_2();
// printf("hehe");
printLinkList(pMyList);

return 0;
}


为何会有错误
printf("your linklist is:\n", p->next->data);
这句话说是有错误,为什么啊
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
tankey0909
C语言 70,039 成员 243,237 内容