The previous article of the topic talked about the first ancestor of the fast sorting-Hall Express, so here we will simply implement the following Hall Express. In addition, a core step of Kubernetes is to select the hub element. the common practice is to use the first element as the hub element, the quick examples and Hoare quick examples in the Introduction to Algorithms are all such pivot elements. The idea of sorting is to select a hub element, and drop all the elements larger than the hub element to the right, and all the elements smaller than the hub element to the left.
The previous article of the topic talked about the first ancestor of the fast sorting-Hall Express, so here we will simply implement Hall Express.
In addition, a core step of Kubernetes is to select the hub element. the common practice is to use the first element as the hub element, the quick examples and Hoare quick examples in the Introduction to Algorithms are all such pivot elements. Let's not talk about efficiency first. let's first look at the implementation of Hoare's fast sorting:
# Include "stdio. h "# include" math. h "# include" stdlib. h "int num = 10; void PrintArray (int arr []) {int I; for (I = 0; I <num; ++ I) {printf ("% d", arr [I]) ;}// after a fast forward, separated by hubs. <= hubs on the left,> = Pivot int Partition (int * arr, int beg, int end) {int low = beg, high = end; // select the pivot int sentinel = arr [beg]; while (low
The program running result is:
Initial array: 80 16 97 6 12 92 31 52 54 89 sorting process: [54 16 52 6 12 31] 80 [92 97 89] Sorting process: [31 16 52 6 12] 54 [80 92 97 89] Sorting process: [12 16 6] 31 [52 54 80 92 97 89] Sorting process: [6] 12 [16 31 52 54 80 92 97 89]) sorting process: [6 12 16 31 52 54 80 89] 92 [97] Final result: 6 12 16 31 52 54 80 89 92 97 Process returned 0 (0x0) execution time: 0.384 sPress any key to continue.
The idea of sorting is to select a hub yuan, and all the elements larger than the hub yuan are dropped to the right, and all the elements smaller than the hub yuan are dropped to the left. you can see:
Is there a clear idea of Hall's fast release?
As mentioned above, both the quick examples and Hoare quick examples in the Introduction to Algorithms use the first element as the pivot element for sorting. Of course there are other selection methods, which will be introduced later.
Additional reading
The topic list of this article is as follows:
- Knowledge in quick sorting: start with guesses
- Knowledge in quick sorting: Let's look at the question of ball.
- Knowledge in quick sorting: Information entropy
- Knowledge in quick sorting: the process of quick sorting
- Knowledge in quick sorting: Hall and quick sorting
- Knowledge in quick sorting: Implementation of Hall's fast sorting
- Knowledge in quick sorting: Key element selection and algorithm efficiency
- Knowledge in quick sorting: randomization fast sorting
This article is available at http://www.nowamagic.net/librarys/veda/detail/2396.