One dimension array selection sorting algorithm in Java array

Source: Internet
Author: User

http://www.verejava.com/?id=16992690199232

 /* Sort by Selection: Idea: 1. Select the smallest of the remaining unordered elements in the array, insert the */public class Selectsort {public static void sort (i Nt[] arrays) {int minindex;//Save the index of the selected minimum for (int i = 0; i < arrays.length-1; i++) {minindex=i            ;                int minvalue=arrays[minindex];//The value of the first element of the loop that holds the minimum value for Each loop for (int j = i; J < Arrays.length-1; J + +) { Compare with each element if the value is less than the minimum value and the index of the saved interchange value is the minimum index if (minvalue>arrays[j+1]) {minvalue=arrays[j+1                    ];                minindex=j+1;                 }} if (I!=minindex)//Determine if the minimum value index changes the current minimum value with the last element to sort {int temp=arrays[i];                Arrays[i]=arrays[minindex];            Arrays[minindex]=temp;        }}} public static void Main (string[] args) {int[] scores={90,70,50,80,60,85};        Sort (scores);        for (int score:scores) {System.out.print (score+ ","); }    }}

http://www.verejava.com/?id=16992690199232

One dimension array selection sorting algorithm in Java array

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.