public class Selectsort {public static void Selectsort (int [] a) {int min; int temp; if (A==null | | a.length<=0) {return;} for (int i=0;i<a.length;i++) {//Outer loop controls the number of times, each time a minimum value is found and the interchange min=i;//defines the current subscript as the lowest value subscript for (int j=i+1;j<a.length;j++) {/ /Inner loop control the comparison between the current trip data find the minimum if (A[j]<a[min]) {//If there is a data in this trip that is less than the minimum value we define then assigns the subscript to min, in fact min is a flag min=j;} } if (min!=i) {//If the min in this trip has changed, then the data in this trip is smaller than the min we defined so the data is exchanged with our definition of a[min] temp=a[min]; a[min]=a[i]; a[i]=temp;}} }
The direct selection sort of Java sort