Non-cyclic bidirectional linked list to realize bubble sort (do not lead node) _ Bidirectional linked list

Source: Internet
Author: User

I am in front of two blog "single linked list (not the lead node) to achieve bubble sort" "single linked list to achieve bubble sort (lead node)" in detail described in the use of the lead node and not the lead node of the single linked table to achieve bubble sort, let's have a rational understanding of the single linked list and bubble sort. Today we're going to use a non-circular doubly linked list without the lead node to do the bubble sort, which is much simpler and more efficient in the process than the previous two. Code uploaded to Https://github.com/chenyufeng1991/DoubleLinkedList_BubbleSort.

The core code is as follows:

Bubble sort
Node *bubblesort (node *pnode) {

    int count = sizelist (pnode);
    Node *pmove;
    Pmove = Pnode;
    Traversal count is count-1 while
    (Count > 1) {while
        (Pmove->next!= NULL) {
            if (Pmove->element > Pmove->n ext->element) {
                int temp;
                Here the data exchange is simpler than the single link table
                temp = pmove->element;
                Pmove->element = pmove->next->element;
                pmove->next->element = temp;
            }
            Pmove = pmove->next;
        }
        count--;
        Back to the head of the list again
        pmove = Pnode;
    }

    printf ("%s function execution, bubble sort complete \ n", __function__);
    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.