//最近上课听关于链表的部分一直不甚明晰,期中考试压着,直到今天才坐下来尝试自己敲链表
//创建链表并输入数
#include<stdlib.h>
#include<malloc.h>
#include<stdio.h>
struct Node
{
int data;
struct Node *next;
};
void Creat(struct Node *phead)
{
struct Node *p,*pnew;
p=(struct Node *)malloc(sizeof(struct Node));
p=phead;
while(110)
{
pnew=(struct Node *)malloc(sizeof(struct Node));
printf("请输入一个数(以0结束输入):");
scanf("%d",&pnew->data);
//printf("data=%d\n",pnew->data);
if(pnew->data==0) break;
p->next=pnew;
pnew->next=NULL;
p=pnew;
}
}
void Print(struct Node *phead)
{
struct Node *pnew;
pnew=(struct Node *)malloc(sizeof(struct Node));
pnew=phead;
printf("输入的数为:\t");
while(pnew->next)
{
pnew=pnew->next;
printf("%d\t",pnew->data);
}
}
int main(void)
{
struct Node *phead;
phead=(struct Node *)malloc(sizeof(struct Node));
phead->next=NULL;
Creat(phead);
Print(phead);
}
;