C Language Selection sorting

Source: Internet
Author: User

//Select Sort, if you need to know the algorithm for finding the minimum and maximum numbers in an array# include<stdio.h># include<stdlib.h># include<time.h>intMain () {//generating an array using time random numberstime_t ts; unsignedintData = Time (&ts);    Srand (data); inta[Ten];  for(inti =0; I <Ten; i++) {A[i]= rand ()% -; printf ("%d\n", A[i]); }     for(inti =0; I <9; i++)    {        intmin = i;//Suppose that the first number is considered the smallest numberprintf"\n%d,%d,%d,%d", I, Min, a[i], a[min]);//Note Column-based observations         for(intj = i +1; J <Ten; J + +)//define the variable J to traverse, notice that the start of the traversal is the second to start        {            if(A[j] < a[min])//If there is a number smaller than the number subscript min, the subscript of the small number is given to min{min=J; }        }        if(min! = i)//if Min is different from the previous I, then you have to Exchange        {            intt =A[min]; A[min]=A[i]; A[i]=T; }    }     for(inti =0; I <Ten; i++) {printf ("%d", A[i]); } System ("Pause");}

C Language Selection 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.