Without consent, please do not reprint! If receipt, please leave a like, be grateful!
At the same time welcome to join us qq exchange group: 326 079 727
Man of few words said on the code:
C Language:
// Select the sort to go from // works: go to achieve a thorough grasp of the principles, selection sort is also similar to bubble sort, the time complexity is O ^ 2, the outer loop is ten. // each round to find the minimum, and then put it in the front, the front has been placed under a comparison would not go void Choice () { int init_arr [ 10 ] = { . 1 , . 5 , . 9 , . 8 , 7 , 6 , 7 , 99 , 8 , 10 }; // get the length of the array, since each type int c language total of four bytes, is divided. 4 int len = the sizeof (init_arr) / . 4 ; int tmp ; for ( int I =0 ; I <len; I ++ ) { // int init_arr mix = [I]; // initialize to mix a first minimum number of array for ( int J = I; J <len; J ++) { // within loop through the layer, find the minimum value, where i bits from the traversing, because (prior to i) has been placed in front of a comparison would not go IF (init_arr [J] <init_arr [i]) { / / how wherein the value of [i] a value smaller than the current value then the switch init_arr tmp = init_arr [i]; init_arr [i] = init_arr [J]; init_arr [J] = tmp; } } // complete a it is able to find the minimum value for this one, and then to the front, the other one will be initialized to a minimum value init_arr [I +. 1] } for ( int= K 0 ; K <len; K ++) { // Loop through print the printf ( " % D \ n- " , init_arr [K]); } }
Python:
# Select the sort to go from DEF Choice (): List = [5,9,88,99,54,66,77,315,88,315,21 ] # selection sort, by definition is selected each round to select the smallest value, then put to the front. for I in Range (0, len (list)): # the outer loop, a find a minimum for J in Range (I, len (list)): # inner loop iterates through the list, comparing the initial value list [j] size, if large, assigned to put minimum list [i], continue ++ J IF (List [I]> list [j]): list [j], List [I] = List [ I], List [J] J + =. 1 # J ++ continue comparing the number of the next I =. 1 + # I ++ for the next round for K in List:# Traversing Print Print (k)