The idea of the bubbling sorting algorithm is to constantly exchange and complete the final sort by swapping.
The basic idea of choosing a sort is that each trip selects the smallest record in the n-i+1 record, which is the record of the first I.
1 voidSimpleselectsort (int*p)2 {3 inti,j,min;4 for(i=0;i<Ten; i++)5 {6min=i; Define the current subscript as the minimum subscript7 for(j=i+1;j<Ten; j + +)8 {9 if(p[min>P[j]]) If there is a value that is less than the current minimumTen { Onemin=J; Assigns the subscript of this value to min A } - } - if(i!=min)//If min is unequal to I, the minimum value is found for Exchange the { - swap (p,i,min); - } - } +}
Features: Low number of moves
Comparison: No matter what the case, the number of comparisons is n-1+n-2+...+2+1=n (n-1)/2
Number of exchanges: preferably 0, worst of n-1
Time complexity O (n2)
C Language Sorting algorithm--Simple selection sorting algorithm