Direct Select sort

Source: Internet
Author: User

The direct selection sort (straight select sorting) is also a simple sorting method, the basic idea is: the first time from r[0]~r[n-1] to select the minimum value, and r[0] Exchange, the second time from the r{1}~r[n-1] to choose the minimum value, and r[1] exchange, ....,

I select the minimum value from r[i-1]~r[n-1], and r[i-1] exchange, ..., the first n-1 from the r[n-2]~r[n-1] in the minimum, and r[n-2] exchange, a total of n-1 times, a sort code from small to large ordered sequence.

//Direct Select SortvoidSortintArray[],intsize) {    intSmall;  for(intI=0; I < size-1; i++)  {      //The I is assumed to be the smallestsmall =i; //start traversing from i+1 to find the lowest subscript of the number larger than I     for(intj=i+1; j<size; J + +)    {        if(array[j]<Array[small]) {Small=J; }      }     //Exchange I and the smallest number found    inttemp =Array[i]; Array[i]=Array[small]; Array[small]=temp; }  }

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.