Offer to come, dig friends take it! I am participating in the 2022 Spring Recruit Punch card activity. Click here for details.

When it comes to sorting algorithms, let’s just sit down and think about it for ten minutes and see how many ways we can come up with.

Let me start with a couple of ideas THAT I’ve come up with.

Method one:

The first round of search, find the largest one, put in the last position; The second round of search, find the second largest, put in the penultimate position….. And you keep going until you get to the last two numbers, and you do a comparison.

Method 2:

First, ensure local order, take this part of the well-ordered data as the base, constantly absorb fresh blood in, and the number of new arrangements to the appropriate position.

Method 3:

Pick a number and compare it with all the numbers, the ones smaller to the left and the ones larger to the right. So you divide one into two, and then you pick another one on the left, and you put it where it should be, and then you divide the other one into two, and so on. And the same thing with the right-hand side. In the end, each part is left with one number, and the position of this number is determined, so we don’t need to compare.

Method 4:

Divide the array to be sorted into several segments, and each segment is sorted. Ensure local order first. Then the two adjacent segments are fused together and sorted side by side. In this way, the two large segments are fused into a whole and sorted.

Method 5:

Using the nature of the heap, the root node of the big top heap, which is the largest number, puts the root node node last. The heap is adjusted to form the big top heap again, and the root node is placed in the second-to-last position. In the end, all the data will be sorted from smallest to largest.

Methods six:

From left to right, adjacent data are compared. If the data on the right is larger than the data on the left, the left and right data are exchanged. After the first round of comparison, the rightmost value must be the largest.

Now that I’ve finished my thinking, let’s take a look at the official names of these methods by referring to the textbook definitions.

Method one is selection sort, method two is insertion sort, method three is quick sort, method four is merge sort, method five is heap sort, method six is bubble sort.

In addition to hill sort, bucket sort, count sort and so on. If we can understand all these kinds of sorting ideas, and we can do it by hand, then the power of the program is still possible.