logo CodeStepByStep logo

reverse

Language/Type: C++ map set vector collections STL
Related Links:

Write a function named reverse that accepts as a parameter a reference to a map from integers to strings, and returns a map with the associations reversed. For example, if a variable named map stores the following key/value pairs:

{1:"a", 2:"b", 3:"c"}

the call of reverse(map); would return the following map:

would yield
{"a":1, "b":2, "c":3}

If there are duplicate values (k1, v) and (k2, v) in the original map, your returned map should contain the pair that would come earlier in sorted order.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.