删除无序链表中值最的节点.C语言实现.2016-04 自考真题

removemax(LinkedList head){
    LinkedList p,q;
    int max;
    if(head->next==NULL)
        return ;
    p=head->next;
    max=p->data;
    while(p->next){
        p=p->next;
        if(p->data>max)
            max=p->data;
    }
    p=head;
    while(p->next){
        q=p->next;
        if(q->data==max){
            p->next=q->next;
            free(q);
            return;
        }
        p=p->next;
    }
}

 

posted @ 2017-03-19 16:52  夜梦多离殇  阅读(227)  评论(0编辑  收藏  举报