Overall Thinking:
1. first, compare the first and second numbers. If the second number is large, use the first number to continue to compare with the third number. Otherwise, use the second number to compare with the third number. If the third number is small, compare the third number with the fourth number, and so on. until the smallest number is found in the number to be sorted, and the number is switched to the first number.
2. Start from the second number and compare it with the third number until the second smallest number is found, and the second number is switched to the second number, and so on.
Package SortSelect;
Public class SortSelect {
Public static void main (String args []) {
Int sortData [] = {4, 1, 2, 3, 8, 6, 5, 9, 11 };
SortSelet (sortData );
System. out. println (sortData );
}
Static int I, j, tmp, min;
Public static void sortSelet (int data []) {
For (I = 0; I <data. length-1; ++ I ){
Min = I;
J = I + 1;
While (true ){
If (j> = data. length)
Break;
If (data [j] <data [min]) {
Min = j;
}
++ J;
}
/*
* Switch location.
*/
Tmp = data [I];
Data [I] = data [min]; // assign the smallest data [I] after each comparison;
Data [min] = tmp;
}
}
}