#include
struct node
{
int n;
struct node *next;
}
main()
{
struct node *head,*p,*q,*r;
int n,m,i=0;
head=(struct node*)malloc(sizeof(struct node));//申请头结点
q=(struct node*)malloc(sizeof(struct node));//申请最后一个节点
head->next=q;//先链接头尾
q->next=NULL;
p=q;
printf("请输入节点个数!\n");
scanf("%d",&n);
printf("请输入节点值!\n");
scanf("%d",&q->n);
//通过循环将结点链接起来
while(i
q=(struct node*)malloc(sizeof(struct node));
scanf("%d",&q->n);
head->next=q; //链接在头结点后面
q->next=p;//指向前一个节点
p=q;
i++;
}
r=head->next;
while(r!=NULL)
{
printf("%d\n",r->n);
r=r->next;
}
}
如还有需要讲解的HI我