/* * * 插入节点 ,使链表保持升序,并返回头节点* * * */
// 最关键两句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;
}
|