Question: Please write in C++ Given a list of random numbers, arrange the list such that the first half of the numbers are sorted in increasing
Please write in C++
Given a list of random numbers, arrange the list such that the first half of the numbers are sorted in increasing order and the second half of the numbers are sorted in decreasing order. You may not use a for-loop to solve this problem.
Starter Code:
#include#include #include #include #include #include static int getRandomNumber(); template std::ostream& operator<<(std::ostream& out, std::vector list) { out << "["; for (const auto& val : list) { out << val << ", "; } out << "]"; return out; } int main() { std::vector list; std::generate_n(std::back_inserter(list), 20, []() { return getRandomNumber(); }); std::cout << list << " "; // TODO: arrange the numbers into a bitonic sequence // NOTE: no for loops, use algorithms } static int getRandomNumber() { static std::mt19937 rng{ std::random_device{}() }; static std::uniform_int_distribution rand{ 0, 100 }; return rand(rng); }
Sample Output:
[10, 23, 90, 60, 66, 97, 92, 93, 64, 85, 94, 34, 69, 48, 69, 97, 84, 80, 29, 100, ] [10, 23, 60, 64, 66, 85, 90, 92, 93, 97, 100, 97, 94, 84, 80, 69, 69, 48, 34, 29, ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
