#include <stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct node
{
int data ;
struct node *pNext;
}NODE,*PNODE;
PNODE creat_list(void);
void traverse_list(PNODE pHead);
int main()
{
PNODE pHead=NULL;
pHead =creat_list();
traverse_list(pHead);
return 0;
}
PNODE creat_list(void)
{
int len;
int i;
int val;
PNODE pHead=(PNODE)malloc(sizeof(NODE));
PNODE pTail=(PNODE)malloc(sizeof(NODE));
pTail=pHead;
pTail->data=NULL;
if(NULL==pHead)
{
printf("malloc err\n");
exit(-1);
}
printf("请输入链表节点的个数:");
scanf("%d",&len);
for(i=0;i<len;++i)
{
printf("请输入%d个节点的值",i+1);
scanf("%d",&val);
PNODE pnew=(PNODE)malloc(sizeof(NODE));
if(NULL==pnew)
{
printf("mallo err");
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");
}
#include<malloc.h>
#include<stdlib.h>
typedef struct node
{
int data ;
struct node *pNext;
}NODE,*PNODE;
PNODE creat_list(void);
void traverse_list(PNODE pHead);
int main()
{
PNODE pHead=NULL;
pHead =creat_list();
traverse_list(pHead);
return 0;
}
PNODE creat_list(void)
{
int len;
int i;
int val;
PNODE pHead=(PNODE)malloc(sizeof(NODE));
PNODE pTail=(PNODE)malloc(sizeof(NODE));
pTail=pHead;
pTail->data=NULL;
if(NULL==pHead)
{
printf("malloc err\n");
exit(-1);
}
printf("请输入链表节点的个数:");
scanf("%d",&len);
for(i=0;i<len;++i)
{
printf("请输入%d个节点的值",i+1);
scanf("%d",&val);
PNODE pnew=(PNODE)malloc(sizeof(NODE));
if(NULL==pnew)
{
printf("mallo err");
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");
}