Data structure _ Select Sort

Source: Internet
Author: User

Select Sort Description

Select sort (Selection sort) is a simple and intuitive sorting algorithm.
The basic idea is to first find the smallest (or largest) element in an unordered sequence, and then store it in the beginning of the sequence, and then continue looking for the smallest (or largest) element from the remaining unsorted elements, and then place it at the end of the sorted sequence. And so on until all elements are sorted.

Summary: Two for loop = one for like i=0-(n-1) + A For loop looking for the coordinates of the smaller array than I save with min + an exchange process

/** set a reference storage coordinate, and the difference between bubbles is not the need for frequent mobile switching, it just need to find the coordinates to save it. */#include"stdio.h"/** Select Sort * * Parameter description: * A--array to be sorted * N--The length of the array*/voidSelect_sort (intA[],intN) {    intI//the end position of the ordered area    intJ//starting position of the unordered area    intMin//the smallest element position in an unordered region     for(i=0; i<n;i++)    {        intflag=1; Min=i;//set a reference storage coordinate, and the difference between bubbles is that there is no need to move frequently         for(j=i+1; j<n;j++)//It starts bubbling, but it doesn't have to be bubbling, so how do you find the smallest?         {            if(a[j]<a[min]) min=j;//to find the smallest a[j of the disordered zone in such a loop] to minflag=0; }        if(!flag)//If the above appears smaller than I exchange, there is no need to exchange        {            intTemp=a[min];//Exchange A[i] and A[min]A[min]=a[i];//a[i]=temp; }       }}voidMainvoid){    inta[]={5,9, -,2,7, -, $,3, -, A,Ten}; intLength=sizeof(a)/(sizeof(a[0])); printf ("before sorting:");  for(intI=0; i<length;i++) printf ("%d", A[i]); printf ("\ n");    Select_sort (a,length); printf ("after selecting sort:");  for(intI=0; i<length;i++) printf ("%d", A[i]); printf ("\ n");}

Data structure _ 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.