Select Sort (ascending)

Source: Internet
Author: User

1, the algorithm think

In the implementation of the selection of sorting, the first part of the entire record sequence is divided into ordered and unordered areas, the initial state ordered area is empty, the unordered area contains all the records to be sorted; the second pair of disordered regions, the record with the smallest key code is exchanged with the first record in the unordered area, and it is repeated to the disordered Area.

2. Algorithm implementation

    Package test;            public class Selectsort {public          static void main (string[] Args) {              int[] n ={1,3,6,2,9,6,8,7};              Selectsort (n);              For (int i:n) {                  System.out.print (i+ "\ t");}          }          public static void Selectsort (int[] arr) {for              (int i = 0;i<arr.length;i++) {                  int min = i;                  for (int j = I+1;j<arr.length;j++) {                      if (arr[min]>arr[j]) {                          min = j;                      }                  }                  If (i!=min) {                      int temp = arr[min];                      arr[min]=arr[i];                      arr[i]=temp;}}}}        

Select Sort (ascending)

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.