Single linked list to realize bubble sort (lead node) __ Bubble Sort

Source: Internet
Author: User

In my previous blog, "single linked list (not the lead node) to achieve bubble sort" to achieve the not the lead node of the single list of bubble sort, breaking the common use of the array to bubble the convention. Then the leading node of the linked list is more commonly used. This blog we are going to implement the lead node of the single linked list bubble sort. It is important to note whether the lead node is critical for handling the first nodes. Code uploaded to: Https://github.com/chenyufeng1991/BubbleSortLinkedList_HeadNode.

The core code is as follows:

Node *bubblesort (node *pnode) {

    int count = sizelist (pnode);//To control the number of

    node *pmove;
    Pmove = pnode->next;

    Traversal count is count-1 while
    (Count > 1) {while
        (Pmove->next!= NULL) {
            if (Pmove->element > Pmove->n ext->element) {
                int temp;
                temp = pmove->element;
                Pmove->element = pmove->next->element;
                pmove->next->element = temp;
            }
            Pmove = pmove->next;
        }
        count--;
        Move back to the first node
        pmove = pnode->next;
    }

    printf ("%s function execution, single linked table bubbling sort succeeded \ n", __function__);
    Printlist (pnode);

    return pnode;
}


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.