One.
Here the previous selection of the sorting operation has been deepened, the selection of the previous discussion is to compare the data on the 0-point mark and the back corner of the data from one after the other, and constantly change the position of the data, until the 0-point mark on the data is the smallest value in the entire array. Because of the number of exchanges, now raises a question, can be directly to the 0-point data and the minimum data for the exchange (if you know the minimum data of the angle mark is how much).
In the previous example, the selection of the sorting, three times to compare the exchange data, so that the data on the corner label 0 is the smallest. Now it's time to change the idea to solve the same problem.
The specific operation is: Define two variables first, why define two variables? A variable record is used to compare the elements of NUM, a variable that records the corner label value.
Think: by video, here is a place where two new variables are opened for recording and then manipulated on the two variables, and the array is not manipulated during the comparison. After all comparisons, two variables record the minimum and minimum values of the corner mark. Finally, the data of the 0-point data in the array and the 4-point data are exchanged directly. This idea compared to the previous problem-solving, carried out a pre-bedding. In fact, I think that the process of thinking, the operation is also quite a lot. The number of comparison records has been increased, and the number of exchanges has been reduced. The two variables are stored in the stack memory.
Java-preliminary Understanding-fifth-arrays-common operations-sorting performance issues