Because in the process of sorting, the decimal places are always put forward and the big ones are put back, which is equivalent to the bubble rising, so it is called bubble sorting.
When using double loop, the outer loop variable is set to I and the inner loop variable is set to J. The outer loop is repeated 9 times, and the inner loop is repeated 9, 8, ..., in turn 1 time. The two elements of each comparison are related to the inner loop J, which can be identified by a[j] and a[j+ 1] respectively, and the value of I is 1, 2, ..., 9 in turn. For each I,
The value of j is 1, 2, ...10-I.
Bubble sorting is stable.
produce
In many programming, we need to sort a sequence for statistics. Common sorting methods include bubble sorting, binary tree sorting and selective sorting. Bubble sorting has always been favored because of its concise thinking mode and high efficiency.
classification process
Suppose that the sorted array r [1...n] stands upright, and each data element is regarded as a weighted bubble. According to the principle that light bubbles cannot be below heavy bubbles, the array R is scanned from bottom to top. When light bubbles that violate this principle are scanned, let them "float" upward, and so on until any two bubbles are light above and heavy below.