In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Selective sorting is one of the sorting algorithms. Here we take sorting from small to large as an example to stop the explanation.
Fundamental ideas and examples
The basic idea of choosing order (from small to big) is, first, choose the smallest number and put it in the first place; then, choose the second smallest number and put it in the second position; and so on, until everything is sorted from small to large.
In terms of completion, we usually confirm the status of the smallest number of locations, and then stop communicating with the number I.
Next, the sorting process is illustrated by sorting the stop selection of 3-2-4-1, and the status of the smallest number of locations in the future is recorded using min_index.
The first round of sorting process (searching for the status of the first small number of locations)
3 2 4 1 (finally, min_index=1)
3 2 4 1 (3 > 2, so min_index=2)
3 2 4 1 (2
< 4, 所以 min_index=2) 3 2 4 1(2 >1, so min_index=4, this time affirms that the first small number is in the position 4)
1 2 4 3 (first round consequence, communication between 3 and 1, that is, communication between status 1 and status 4)
The second round of sorting process (looking for the status of the second smallest number of locations)
1 2 4 3 (first round consequence, min_index=2, only need to start from position 2)
1 2 4 3 (4 > 2, so min_index=2)
1 2 4 3 (3 > 2, so min_index=2)
1 2 4 3 (second round consequence, as min_index happens to be in the second position, no communication is required)
The third round of sorting process (looking for the status of the third smallest number of locations)
1 2 4 3 (second round consequence, min_index=3, only need to start with status 2)
1 2 4 3 (4 > 3, so min_index=4)
1 2 3 4 (the third round of consequences, 3 and 4 exchanges, that is, status 4 and status 3 exchanges)
At this point, the ranking is over.
Summary and completion
Select sort stops sorting on the unordered array R [N] of size N, and stops the NMUI 1-round selection process. The I round pulls out the I lowest number and puts it in the I position. When the N-1 is completed, the number of the N-th (that is, the largest) is naturally in the initial position.
The C language completion of the selection sort is given below.
# include # include # define N 8 void select_sort (int a [], int n); / / Select the number of elements that finish sorting void select_sort (int a [], int n) / / n is the number of elements of the array a {/ / stop the first round of selection for (int item0; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.