Implementation of the "Java" selection sort

Source: Internet
Author: User

Select the principle of sorting:

First trip: 0 The foot mark is compared with the following keywords, if the keyword is less than the 0-pin keyword, then the location of two keywords is exchanged; After the first simple selection of sorting, the 0 pin is the smallest record in all keywords.

Second trip: 1 The foot mark is compared with the following keywords, if the keyword is less than the 1-pin keyword, the location of the two keywords is exchanged; After a second pass, a simple selection is ordered, and the 1-foot mark is the smallest record in any other keyword except the 0-foot-key keyword.

.

.

And so on

.

.

Code implementation:

public class  Select Sort  {    public static void main (String[]  args)     {        int []a=new int[ ]{56,34,21,45,75,24,1,1,5};        print (a);         //int []b=new int[a.length];         Choosesort (a);         print (a);    }     public static void choosesort (int a[])     {         for (int i=0;i<a.length;i++)          {            for (int j=i+1;j< a.length;j++)             {         &nBsp;       if (A[i]>a[j])                  {                     int m;                     m=a[i];                     a[i]=a[j ];                     a[j]=m;                 }                 continue;            }         }&nBsp;   }    public static void print (int a[])      {        for (int x=0;x<a.length;x++)          {             if (x!=a.length-1)                  system.out.print (a[x]+ ",");             else                 System.out.print (A[x]);        }         //return int;        system.out.println ();     }}


Implementation of the "Java" selection 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.