Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a vector of values each of which is larger than zero, for each value, find the closest element that comes before it and is

Given a vector of values each of which is larger than zero, for each value, find the closest element that comes before it and is larger than it. For example, consider the following input vector.

10 5 9 70 200 50 70 300 75 120 180 130 95 310 360 72 78 400 30 22
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

For this input vector, your function should produce the following output vector.

0 10 10 0 0 200 200 0 300 300 300 180 130 0 0 360 360 0 400 30
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

I need help with this assignment both iteratively and recursively. (Two separate main files for each version).

void largest_left_iterative(const std::vector &numbers, std::vector &result); // iterative prototype

void largest_left_recursive(const std::vector &numbers, std::vector &result, int n); // Recursive prototype

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions