12. Single-linked list sorting

Source: Internet
Author: User

12. Single-linked list sorting

Ideas:

See basic function 13://bubble sort list, the practice is "Civet cat for Prince", that is, only the value of the Exchange node, the structure of the list does not change.

void Sortlist (node*& Head);

List sorting//sorting method is not to destroy the structure, there is "Civet cat for Prince" meaning, only the exchange of value, do not destroy the list structure void Sortlist (node*& head) {    int count=numofnodes (head) ;    if (count==0| | Count==1)    {        return;    }    Bubble sort    bool Exchange; for    (int i=2;i<=count;i++)    {        exchange=false; for        (int j=count;j>=i;j--)        {            node* P1=locatenodei (head,j);              node* P2=locatenodei (head,j-1);             if (p1->value<p2->value)            {            exchange=true;              Swap (p1->value,p2->value);         }         }         if (!exchange) break       ;    }}

  

12. Single-linked list sorting

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.