带头结点的链表冒泡排序

//链表冒泡排序
void bubble_sort_link(const Link p_head)
{
    Link p = NULL;
    Link q = NULL;
    Link tail = NULL;

    while (p_head->p_next != tail)
    {
        p = p_head;
        q = p_head->p_next;

        while (q->p_next != tail)
        {
            if (strcmp((const char*)q->name, (const char*)q->p_next->name) > 0)
            {
                p->p_next = q->p_next;
                q->p_next = q->p_next->p_next;
                p->p_next->p_next = q;
                q = p->p_next;
            }
            q = q->p_next;
            p = p->p_next;
        }
        tail = q;
    }
}

 

你可能感兴趣的:(带头结点的链表冒泡排序)