java-Selection Sorting method

Source: Internet
Author: User

1. Idea: in ascending order, each time you find the lowest subscript, and then swap with the current loop

2. Code

1  Public classTestarray {2     3      Public Static voidMain (string[] args) {4         int[] Array =New int[args.length];5          for(inti = 0; i < args.length; i++){6Array[i] =Integer.parseint (Args[i]);7         }8         9System.out.println ("before sorting");Ten          for(intI:array) { OneSystem.out.print (i+ "\ T"); A         } -          -System.out.println ("\ n sort after"); the         //Arrays.sort (array); - Testarray.selectedsort (array); -          for(intI:array) { -System.out.print (i+ "\ T"); +         } -     } +      A      Public Static voidSelectedsort (int[] Array) { at          for(inti = 0; i < Array.Length; i++){ -             intindex =i; -              for(intj = i; J < Array.Length; J + +){ -                 if(Array[index] >Array[j]) { -index =J; -                 } in             } -             if(i!=index) { to                 inttemp =Array[i]; +Array[i] =Array[index]; -Array[index] =temp; the             } *              $         }Panax Notoginseng     } -  the}

3.java Testarray 3 7 6 9 operation Result is

java-Selection Sorting method

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.