带头结点的链表冒泡排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a_studycx/article/details/82620277
//链表冒泡排序
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;
    }
}

猜你喜欢

转载自blog.csdn.net/a_studycx/article/details/82620277