This should be the most basic sorting algorithm.
Specific operations are as follows:
As you can see, this algorithm is characterized by constantly increasing the number of sorted items like bubbles.
The specific procedure is as follows:
/* Implement with a double loop. Set the External Loop Variable to I and the inner loop variable to j. The External Loop repeats 9 times, and the inner loop repeats 9, 8,..., 1 time in sequence. The two elements for each comparison are related to the inner loop j, which can be identified by a [j] And a [j + 1] respectively, the values of I are 1, 2 ,..., 9. For each I, j values are 1, 2 ,... 10-i. * // * If there are n numbers, n-1 comparison (and exchange) is required ). In the first round, we need to perform the n-I comparison, and in the second I, we need to perform the n-I comparison. */# Include <stdio. h> int main () {int a [10]; int I, j, temp; printf ("please enter ten numbers: \ n"); for (I = 0; I <10; I ++) {scanf ("% d", & a [I]) ;}for (I = 0; I <9; I ++) // perform 9 comparisons in total {for (j = 0; j <9-i; j ++) // perform (10-i) in each query) {if (a [j]> a [j + 1]) // if the first number is greater than the next one, exchange two numbers {temp = a [j]; a [j] = a [j + 1]; a [j + 1] = temp ;}}} for (I = 0; I <10; I ++) {printf ("% d \ t", a [I]);} printf ("\ n "); return 0 ;}