Direct Select sort

Source: Internet
Author: User

Direct Select sort

A. The 1th trip from which to find the smallest, with R0 exchange

B. 2nd trip Find the smallest from the remainder, with the R1 exchange

........................................................


The code is as follows

 

Directly select sort        void selectsort (int []a,int N)        {            //define variable            int i, J, Nminindex;            for (i=0;i<n;i++)            {                //min. flag bit                nminindex = i;                Loop find minimum                for (j=i+1;j<n;j++)                {                    //Compare                    if (A[j] < A[nminindex])                    {                        //if less than, Flag bit Change                       nminindex = j;                                           }                                                      }               After the above loop find the minimum                if (nminindex!=i)                {                    ///value to exchange                    int c = a[i];                    A[i] = A[nminindex];                    A[nminindex] = c;}}        }

bubble vs. Direct selection sort comparison

In fact, the direct selection of the sort is much like bubble sort, but it is better than bubbling is not always bubbling, that is, the data exchange, but the bubble is better than it is that, if the order is already in place, you can directly stop




Direct Select sort

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.