struct node *add (struct node *head, int n)
{
struct node *p,*end;
p=(struct node*)malloc(sizeof(struct node));
p->data=n;
p->next=NULL;
end=head;
if(end!=NULL)//不是空链表
{
while(end->next!=NULL)
{
end=end->next;//移动到链表尾部
}
end->next=p;//将节点添加至链表尾部
}
else
{
head=p;//如果为空链表,直接将节点放头部
}
return head;
}