Select the sort array

Selection sort works: the number of columns in unsorted, find the maximum (minimum) with an unsorted the last (first) exchange. As shown below (ps pictures from the network, if infringement please contact deleted):

 

First: Find the maximum of the element 9, and then exchanged with the last position.
Second: find the maximum value for the element 8, then the last non-sorted (the entire number of columns penultimate) exchange.
third: find the maximum of the element 7, then with unsorted last (the reciprocal of the entire series of the third) to be exchanged.
....
implementation code

 


The code is implemented mainly includes three steps:
STEP 1: the position of unsorted maximum number of columns, the number of columns is usually the first choice location
Step: The maximum value is compared with each of a number of columns, if less than the maximum number of columns of a certain value, the maximum value position changes, so each one will be able to find out the location of unsorted maximum number of columns.
The third step: the maximum value and the last value of unsorted exchange columns.

 

Guess you like

Origin www.cnblogs.com/login123/p/12013068.html