struct link *lianbiao(struct link *head,int n,char id[10],char password[10])/*登录链表*/
{ //括号内传入想要传入的参数
struct link *p=NULL,*pr=head; 设置一个空节点和一个头节点
p=(struct link *)malloc(sizeof(struct link));//申请节点空间
if(p==NULL)
{
printf("系统错误");
return 0;
}
if(head==NULL)//如果头节点是空,那么将头节点设置成p
{
head=p;
}
else
{//如果头节点不是空,那么将我们的这个p节点插入链表的尾部
while(pr->next!=NULL)
{
pr=pr->next;
}
pr->next=p;
}
//将我们的p节点进行赋值
strcpy(p->id,id);
strcpy(p->password,password);
p->n=n;
p->next=NULL;
return head;
}
c语言的链表的添加节点
最新推荐文章于 2024-04-21 22:19:51 发布