uint64_t current_position = 0) {
58 if(current_position + 1 == in_arr.size()) {
59 returncurrent_position;
61uint64_t answer =
findMinIndex(in_arr, current_position + 1);
62 if(in_arr[current_position] < in_arr[answer]) {
63answer = current_position;
77uint64_t current_position = 0) {
78 if(current_position == in_arr.size()) {
81uint64_t min_element_idx =
83 if(min_element_idx != current_position) {
84std::swap(in_arr[min_element_idx], in_arr[current_position]);
98std::vector<uint64_t> array1 = {0, 1, 1, 2};
99std::cout <<
"1st test... ";
101assert(std::is_sorted(std::begin(array1), std::end(array1)));
102std::cout <<
"passed"<< std::endl;
105std::vector<uint64_t> array2 = {1, 0, 0, 1, 1, 0, 2, 1};
106std::cout <<
"2nd test... ";
108assert(std::is_sorted(std::begin(array2), std::end(array2)));
109std::cout <<
"passed"<< std::endl;
112std::vector<uint64_t> array3 = {1, 1, 0, 0, 1, 2, 2, 0, 2, 1};
113std::cout <<
"3rd test... ";
115assert(std::is_sorted(std::begin(array3), std::end(array3)));
116std::cout <<
"passed"<< std::endl;
119std::vector<uint64_t> array4 = {2, 2, 2, 0, 0, 1, 1};
120std::cout <<
"4th test... ";
122assert(std::is_sorted(std::begin(array4), std::end(array4)));
123std::cout <<
"passed"<< std::endl;
Functions for the Selection sort implementation using recursion.
uint64_t findMinIndex(const std::vector< T > &in_arr, uint64_t current_position=0)
The main function finds the index of the minimum element.
static void test()
Self-test implementations.
void selectionSortRecursive(std::vector< T > &in_arr, uint64_t current_position=0)
The main function implements Selection sort.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4