美文网首页
36.写一函数insert,用来向动态链表插入一结点

36.写一函数insert,用来向动态链表插入一结点

作者: vbuer | 来源:发表于2018-09-02 12:47 被阅读13次
Student *insert(student *head, student *stud)
 {
    student *p0 ,*p1, *p2;
    p1=head;
    p0=stud;
    if(head == NULL)
    {
        head=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num >p1->num) && (p1->next!=NULL) )
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num <= p1->num)
        {
            if(head ==p1)
                head=p0;
            else
                p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;  
        }
    }
    n=n+1;
    return(head);
  
 }

相关文章

网友评论

      本文标题:36.写一函数insert,用来向动态链表插入一结点

      本文链接:https://www.haomeiwen.com/subject/nycmwftx.html