std::vector<T>
waveSort(
conststd::vector<T> &in_arr, int64_t n) {
35std::vector<T> arr(in_arr);
37 for(int64_t i = 0; i < n; i++) {
40std::sort(arr.begin(), arr.end());
41 for(int64_t i = 0; i < n - 1; i += 2) {
42std::swap(arr[i], arr[i + 1]);
55std::vector<int64_t> array1 = {10, 90, 49, 2, 1, 5, 23};
56std::cout <<
"Test 1... ";
58 conststd::vector<int64_t> o1 = {2, 1, 10, 5, 49, 23, 90};
60std::cout <<
"passed"<< std::endl;
63std::vector<int64_t> array2 = {1, 3, 4, 2, 7, 8};
64std::cout <<
"Test 2... ";
66 conststd::vector<int64_t> o2 = {2, 1, 4, 3, 8, 7};
68std::cout <<
"passed"<< std::endl;
71std::vector<int64_t> array3 = {3, 3, 3, 3};
72std::cout <<
"Test 3... ";
74 conststd::vector<int64_t> o3 = {3, 3, 3, 3};
76std::cout <<
"passed"<< std::endl;
79std::vector<int64_t> array4 = {9, 4, 6, 8, 14, 3};
80std::cout <<
"Test 4... ";
82 conststd::vector<int64_t> o4 = {4, 3, 8, 6, 14, 9};
84std::cout <<
"passed"<< std::endl;
Functions for the Wave sort implementation.
std::vector< T > waveSort(const std::vector< T > &in_arr, int64_t n)
The main function implements that implements the Wave Sort algorithm.
static void test()
Self-test implementations.
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