Java selection Sort

Source: Internet
Author: User

Choosing a sort (select sorting) is also a simple sort method. Its basic ideas are:

First select the minimum value from r[0]-r[n1], swap with r[0],

The second time from r[1]-r[n-1] to select the minimum value, and r[1] exchange,

The third time from r[2]-r[n-1] to choose the minimum value, and r[2] exchange, ...,

I select the minimum value from r[i-1]-r[n-1], swap with r[i-1], ...,

Section n-1 from r[n-2]-r[n-1] to select the minimum value, and r[n-2] exchange, a total of n-1 times, to get a sort code from small to large order sequence.

 Packagesorting; Public classsecectionsorting {//Select Sort     Public Static voidMain (string[] args) {//TODO auto-generated Method Stub              intarr[]={2,5,11,23,14,12,20,17}; intTemp=0;  for(inti=0;i<arr.length-1;i++){          //Suppose the first one is the smallest number          intmin=Arr[i]; //record the smallest subscript          intminindex=i;  for(intk=i+1;k<arr.length;k++){              if(min>Arr[k]) {                  //Modify Minimum Valuemin=Arr[k]; Minindex=K; }          }          //This minimum value is found when the outer for loop is introduced.temp=Arr[i]; Arr[i]=Arr[minindex]; Arr[minindex]=temp; }      //The Foreach method iterates through the sorting results of the output array a       for(intE:arr) {System.out.print (e+ "<"); }    }}

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.