链表中升序删除结点

//升序删除结点
void Min_delete(LinkList &L)
{
    LinkList pre,p;
    while(L->next)
    {
        pre = L;//存放最小结点的前驱
        p = L->next;//工作指针

        while(p->next)
        {
            if(p->next->data<pre->next->data)
            {
                //找到比当前还要小的结点
                pre = p;
                p = p->next;
            }
            print(pre->next->data);

            pre->next = p->next;
            free(p);

        }

    }

    free(L);
}

 

点赞