Current location - Loan Platform Complete Network - Big data management - Usage of c# bubble sorting
Usage of c# bubble sorting
The basic concept of BubbleSort is to compare two adjacent numbers in turn, with the decimal number in front and the large number in the back. That is, first compare the 1 th number with the second number, with the decimal number first and the large number last. Then compare the second number with the third number, with decimals in front and large numbers behind, and so on until the last two numbers are compared, with decimals in front and large numbers behind. Repeat the above process, still compare from the first logarithm (because the second number and the third number are interchanged, 1 number may not be less than the second number), put the decimal number in front and the large number in the back, compare to a pair of adjacent numbers in front of the maximum number, put the decimal number in front and the large number in the back, and end the second time to get a new maximum number in the penultimate number. And so on until the sorting is finally completed.

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.