How to use C++ Recursion to implement selection sorting algorithm
This article mainly introduces how to use C++ recursion to achieve the selection sorting algorithm, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article. Next, let the editor take you to know about it.
Basic thought
Each time you find the smallest element, use the exchange implementation to put it in the first place in disorder until all the elements have been sorted.
Give an example
Take A [10] = {3] 1, 6, 4, 8, 2, 10, 7, 9, 5} as an example
The first selection sort: sort position 0, element 1 is the smallest element after position 0, then swap (A [0], A [1])
That is, 1, 3, 6, 4, 8, 2, 10, 7, 9, 5, then position 0 is ordered, and position 0 is out of order.
The second selection sort: sort position 1, element 1 is the smallest element after position 1, then swap (A [1], A [5])
That is, 1 2 6 4 8 3 10 7 9 5, then position 1 is in order, and position 1 is disordered after position 1.
... ...
Complete code / / Select sort, compilation environment Dev C++#include # include using namespace std;void sort (int spenint treint arr []) / a pair of arr [s.t] to select sort {if (s)