#include<stdio.h>
struct Ai
{
int a;
struct Ai *next;
};
struct Ai *re()
{ struct Ai *head,*new,*pend;
int n,i=0;
head=NULL;
new=(struct Ai *)malloc(sizeof(struct Ai));
printf("输入节点数\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i==1)
{
head=new;
pend=head;
}
else
{
pend->next=new;
pend=new;
}
pend->next=NULL;
printf("输入第%d个节点的数:\n",i);
scanf("%d",&new->a);
new=(struct Ai *)malloc(sizeof(struct Ai));
}
return(head);
}
void chu(struct Ai *head)
{
struct Ai *p;
int n=1;
p=head;
while(p!=NULL)
{
printf("第%d个节点数为%d\n",n,p->a);
p=p->next;
n++;
}
printf("第%d个节点数为:%d\n",n,p->a);
}
void main()
{
struct Ai *head;
head=re();
printf("节点数如下:\n");
chu(head);
}
struct Ai
{
int a;
struct Ai *next;
};
struct Ai *re()
{ struct Ai *head,*new,*pend;
int n,i=0;
head=NULL;
new=(struct Ai *)malloc(sizeof(struct Ai));
printf("输入节点数\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i==1)
{
head=new;
pend=head;
}
else
{
pend->next=new;
pend=new;
}
pend->next=NULL;
printf("输入第%d个节点的数:\n",i);
scanf("%d",&new->a);
new=(struct Ai *)malloc(sizeof(struct Ai));
}
return(head);
}
void chu(struct Ai *head)
{
struct Ai *p;
int n=1;
p=head;
while(p!=NULL)
{
printf("第%d个节点数为%d\n",n,p->a);
p=p->next;
n++;
}
printf("第%d个节点数为:%d\n",n,p->a);
}
void main()
{
struct Ai *head;
head=re();
printf("节点数如下:\n");
chu(head);
}