C Language Sorting algorithm--Simple selection sorting algorithm

Source: Internet
Author: User

The idea of the bubbling sorting algorithm is to constantly exchange and complete the final sort by swapping.

The basic idea of choosing a sort is that each trip selects the smallest record in the n-i+1 record, which is the record of the first I.

1 voidSimpleselectsort (int*p)2 {3     inti,j,min;4      for(i=0;i<Ten; i++)5     {6min=i; Define the current subscript as the minimum subscript7          for(j=i+1;j<Ten; j + +)8         {9             if(p[min>P[j]]) If there is a value that is less than the current minimumTen             {     Onemin=J; Assigns the subscript of this value to min A             } -         } -         if(i!=min)//If min is unequal to I, the minimum value is found for Exchange the         { - swap (p,i,min); -         } -     } +}

Features: Low number of moves

Comparison: No matter what the case, the number of comparisons is n-1+n-2+...+2+1=n (n-1)/2

Number of exchanges: preferably 0, worst of n-1

Time complexity O (n2)

C Language Sorting algorithm--Simple selection sorting algorithm

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.