链表实现尾插法(C语言)

来源:百度知道 编辑:UC知道 时间:2024/06/24 09:03:36

据个例子:
#include <stdio.h>
#define LEN sizeof(struct A)
#define NULL 0
struct A
{ int a;
struct A* next;
};
struct A* new() /*建立链表的函数,返回链表头指针*/
{ struct A *p1,*p2,*head;
head=p2=p1=(struct A*)malloc(LEN);
scanf("%d",&p1->a;)
while(p2->a!=2155)/*以2155作为输入节点的结束标志*/
{p1=(struct A*)malloc(LEN);
scanf("%d",&p1->a);
p2->next=p1;
p2=p1;
}
p1->next=NULL;
return head;
}