Simple sorting algorithm - Selection Sort

Selection Sort:
Selection Sort (Selection sort) is a straightforward sorting algorithm. It works every time the data element to be selected from the sorted minimum (or maximum) of an element stored in the starting position of the sequence, until all the data elements to be sorted drained.

Selection sort is unstable sorting method (such as the sequence [5,5, 3] will be the first of a [5] and [3] exchange, resulting in a 5 to move to the first after the second 5).

Select the sort that white is the index to sort.

Man of few words said on the code. "" "

 

package sdx;

import java.util.Arrays;

{class Main7 public
public static void Main7 (A int []) {
for (int I = 0; I <a.length; I ++) {
int minIndex = I;
for (int I = J +. 1; J <a.length ; J ++) {
IF (a [J] <a [minIndex]) {
minIndex = J;
}
} // after this step, just to find a minimum index lower,
! IF (I = minIndex) {// find minimum index, replacing i (premise is i and the minimum index value minindex not equal, because equal exchange not sense)
int TEMP = A [i];
A [i] = A [minindex];
A [minindex] = TEMP;
}
}

}

static void main public (String [] args) {
// TODO method of automatically generating stubs
int A [] = {} 12,4,5,123,6,8,54,234,123;
of System.out.print ( "before the array is sorted : "+ of Arrays.toString (A));
System.out.println ();
Main7 new new Main7 SS = ();
// ss.Main7 (A, 0,. 1-a.length);
ss.Main7 (A) ;
of System.out.print ( "sorted array is:" + of Arrays.toString (a));
}

}

Guess you like

Origin www.cnblogs.com/sdx-BK/p/12005459.html
Recommended