Description of several sorting methods
Quick sorting is to take out an element, put the smaller one on the left and the larger one on the right, and then continue to sort the left and right sequences. Usually this element is the first in the sequence, because it is simpler and needs no thinking. For example, 4, 2, 7 and 5 are sorted as follows: 2, (4), 7 and 5. Bubble sorting is the comparison of two adjacent elements, the first is the second, the second is the third, and the big one is the third ... Once you go from left to right, the biggest one will be found and placed on the far right. For example: 4, 2, 7, 5 The first comparison: 2, 4, 7, 5 The second comparison: 2, 4, 7, 5 The third comparison: 2, 4, 5, 7 is directly inserted into the sorting, that is, an element is placed in an ordered sequence, and its end is looked at first. If it does not meet the order requirements, it is placed in the penultimate one. Look. For example, 4, 2, 7, 5 is considered orderly when there is only one 4 the first time. So the result is: 4, 2, 7, 5 The second time, taking 2 into account, I found that it was smaller than the previous 4, so the order was wrong. Let's exchange them, so it was: 2, 4, 7, 5. Then keep reading and find that 2 has reached the front, so let's end it. Considering 7 for the third time, it is found to be bigger than the first 4, so the order is correct. The results are: 2, 4, 7, 5. The fourth time, considering 5, it is found that it is less than 7, and the exchange is greater than the previous 4. All right, we can set the position. The result is that the final heap sorting of 2, 4, 5 and 7 is troublesome, and the meaning of the heap should be considered. Take a small pile as an example, it is like a pile of golden pagodas (triangles). There are always two feet at the top, so the element at the top is the smallest, and the largest one must be at the bottom, and its position is not fixed. Heap sorting is to take the smallest one at a time (the example of a small heap), that is, the top one. After you take it out, rearrange other elements into a small heap, and then take the next smallest element at the top, so that all elements are always taken out, and the order you take is the result of sorting. Example:. . . 3。 . . . . 4。 . 5。 . 5。 6。 The scheme adopted is to exchange the smallest and last positions and take out the uppermost position. . . . 9.。 . . . . 4.。 . 5.。 . 5。 6.。 Note 3 is the first one to be taken out and can be considered as non-existent. Then sort out this pile and sort out the triangle of 9-4-5, which becomes:. . 4.。 . . . . 9.。 . 5.。 . 5.。 6.。 . . See that the triangle in the lower left corner does not conform to the rules, and continue to organize. . . 4.。 . . . . 5.。 . 5.。 . 9.。 6.。 . . All right, all the elements are piled up again. In each triangle, the lower one is bigger than the upper one. You can take down the next smallest element. The above explanation is vague. If you have any questions, please keep in touch.