34std::vector<T>
waveSort(
const std::vector<T> &in_arr, int64_t n) {
35 std::vector<T> arr(in_arr);
37 for (int64_t i = 0; i < n; i++) {
40 std::sort(arr.begin(), arr.end());
41 for (int64_t i = 0; i < n - 1; i += 2) {
42 std::swap(arr[i], arr[i + 1]);
55 std::vector<int64_t> array1 = {10, 90, 49, 2, 1, 5, 23};
56 std::cout <<
"Test 1... ";
57 std::vector<int64_t> arr1 = sorting::wave_sort::waveSort(array1, 7);
58 const std::vector<int64_t> o1 = {2, 1, 10, 5, 49, 23, 90};
60 std::cout <<
"passed" << std::endl;
63 std::vector<int64_t> array2 = {1, 3, 4, 2, 7, 8};
64 std::cout <<
"Test 2... ";
65 std::vector<int64_t> arr2 = sorting::wave_sort::waveSort(array2, 6);
66 const std::vector<int64_t> o2 = {2, 1, 4, 3, 8, 7};
68 std::cout <<
"passed" << std::endl;
71 std::vector<int64_t> array3 = {3, 3, 3, 3};
72 std::cout <<
"Test 3... ";
73 std::vector<int64_t> arr3 = sorting::wave_sort::waveSort(array3, 4);
74 const std::vector<int64_t> o3 = {3, 3, 3, 3};
76 std::cout <<
"passed" << std::endl;
79 std::vector<int64_t> array4 = {9, 4, 6, 8, 14, 3};
80 std::cout <<
"Test 4... ";
81 std::vector<int64_t> arr4 = sorting::wave_sort::waveSort(array4, 6);
82 const std::vector<int64_t> o4 = {4, 3, 8, 6, 14, 9};
84 std::cout <<
"passed" << std::endl;