The direct selection sort (straight select sorting) is also a simple sorting method, the basic idea is: the first time from r[0]~r[n-1] to select the minimum value, and r[0] Exchange, the second time from the r{1}~r[n-1] to choose the minimum value, and r[1] exchange, ....,
I select the minimum value from r[i-1]~r[n-1], and r[i-1] exchange, ..., the first n-1 from the r[n-2]~r[n-1] in the minimum, and r[n-2] exchange, a total of n-1 times, a sort code from small to large ordered sequence.
//Direct Select SortvoidSortintArray[],intsize) { intSmall; for(intI=0; I < size-1; i++) { //The I is assumed to be the smallestsmall =i; //start traversing from i+1 to find the lowest subscript of the number larger than I for(intj=i+1; j<size; J + +) { if(array[j]<Array[small]) {Small=J; } } //Exchange I and the smallest number found inttemp =Array[i]; Array[i]=Array[small]; Array[small]=temp; } }
Direct Select sort