Non-cyclic bidirectional linked list realizes bubble sort (lead node end node) __ Head Node

Source: Internet
Author: User

In my previous blog, I made a bubble sort of three different lists, distinguishing types with single linked lists and two-way lists, with leading nodes and not leading nodes. In fact, the overall idea is the same, respectively, to (n-1) time to traverse the list, compare the size of the two nodes before and after the exchange. In order to learn the integrity of this blog, we will be able to achieve the lead node in the bidirectional non cyclic chain table bubble sort. Code uploaded to Https://github.com/chenyufeng1991/DoubleLinkedList_NodeList_BubbleSort.

The core code is as follows:

Bubble sort
void Bubblesort (Node *phead,node *ptail) {

    int count = Sizelist (Phead, ptail);
    Node *pmove;
    Pmove = phead->next;

    while (Count > 1) {while
        (Pmove->next!= ptail) {
            if (Pmove->element > Pmove->next->element) { c7/>//Exchange
                int temp;
                temp = pmove->element;
                Pmove->element = pmove->next->element;
                pmove->next->element = temp;
            }
            Pmove = pmove->next;
        }
        Pmove = phead->next;
        Count--;
    }

    printf ("%s function execution, list bubbling sort complete \ n", __function__);
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.