Compare the size of several numbers

When learning C language, I first learned the comparison method of two numbers and three numbers. The following is the comparison method of three numbers:

3e88de5c213c4df89dbb416107a83bd1.png

 In this method, it is necessary to compare every two numbers and exchange them with the intermediate variable t. If there are more than 3 numbers, this method is very troublesome.

So we can put a string of numbers in an array and compare them using the bubble method.

The basic idea of ​​the bubble method is: compare two adjacent numbers each time, and move the smaller one to the front. If there are n numbers, n-1 comparisons are required. In the first comparison, n-1 pairwise comparisons are performed, and nj pairwise comparisons are performed in the j-th comparison. After each comparison and exchange, the smallest number "rises" one bit, and finally rises to the first number. This is like the bubbles at the bottom of the water gradually emerging from the water surface, so it is called the bubbling method or the bubbling method.

The procedure is as follows:c1294741dfc642538922ae1ddb8d9c00.png

 

 

Guess you like

Origin blog.csdn.net/m0_73939236/article/details/128021263