Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

Students also viewed these Databases questions

Question

What are the two asset valuation models?

Answered: 1 week ago