[技术讨论] 关于链表插入节点,麻烦有人帮忙看一下有没有问题?

[复制链接]
 楼主| 畅想天子 发表于 2022-5-26 14:02 | 显示全部楼层 |阅读模式
/* * * 插入节点 ,使链表保持升序,并返回头节点* * * */
// 最关键两句p->next =s; s->next =p->next;有没有问题?
struct student *insert(struct student *head,struct student *s)
{
struct student *p=head;
while((p->next!=NULL)&&(s->score>p->next->score))
  p=p->next;
  if(p->next==NULL)
  {
   p->next =s;
   s->next =NULL;
  }
  else
  {
   p->next =s;
   s->next =p->next;
  }
  return head;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

58

主题

333

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

58

主题

333

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部