3 建立动态链表
学自徐洪波c语言教程
#include<stdio.h>
#include<malloc.h>
// 链表结构体
struct node
{
int value;
struct node * next;
}
void creat()
{
struct node * root;
struct node * tail;
struct node *p;
p=(struct node *)malloc(sizeof(node));
scanf("%d",&p->value);
if(NULL!=p)
{
root =p;
tail =p;
}
while(p->value!=0)
{
p=(struct node*)malloc(sizeof(node));
scanf("%d",&p->value);
if(p!=NULL)
{
tail->next=p;
tail=p;
}
}
}
void main()
{
struct std *q= creat_link();
while(q->num != 0)
{
printf("节点%d /n",q->num);
q=q->next;
}
/*
while(q != NULL)
{
printf("节点%d /n",q->num);
q=q->next;
}
*/
}