#include
#include
#include
typedef struct Node
{
int data;
struct Node* pNext;
}NODE,*PNODE;
PNODE create_list(void);
void traverse_list(PNODE pHead);
int main(void)
{
PNODE pHead = NULL;
pHead = create_list();
traverse_list(pHead);
return 0;
}
PNODE create_list(void)
{
int len;
int i;
int val;
PNODE pHead=(PNODE)malloc(sizeof(NODE));
if(NULL==pHead)
{
printf("Allocate is failed\n");
exit(-1);
}
PNODE pTail = pHead;/* 此处 问题!!!*/
pTail->pNext=NULL;
printf("Please input list number:len= ");
scanf("%d",&len);
for(i=0;i<len;i++)
{
printf("Please input %d th node number", i+1);
scanf("%d",&val);
PNODE pNew = (PNODE)malloc(sizeof(NODE));
if(NULL==pNew)
{
printf("Allocate is failed\n");
exit(-1);
}
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=p->pNext;
}
printf("\n");
return;
}