#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct Node
{
int data;//数据域
struct Node*pNext;//指针域
} NODE,*PNODE;
PNODE create_list(void)
{
int len;//节点的个数
int i;
int val;//存储结点的值
PNODE phead=(PNODE)malloc(sizeof(NODE));
PNODE pTail=phead;
pTail->pNext=NULL;
printf("请输入您需要的节点数;len=");
scanf("%d",&len);
for(i=0;i<len;++i)
{
printf("请输入第%d个结点的值:",i+1);
scanf ("%d,&val");
PNODE pNew=(PNODE)malloc(sizeof(NODE));
pNew->data=val;
pTail->pNext=pNew;
pNew->pNext=NULL;
pTail=pNew;
}
return phead;
}
void traverse_list(PNODE phead)
{
PNODE p=phead->pNext;
while (NULL !=p)
{
printf("%d",p->data);
p->pNext;
}
printf("\n");
}
int main(void)
{
PNODE phead= NULL;
phead= create_list();
traverse_list(phead);
return 0;
}
为什么出现了一堆堆的0000000?