logo CodeStepByStep logo


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

Write a function numInCommon that accepts as parameters two references to vectors of integers, and returns a count of the number of unique integers that appear in both vectors. Use one or more sets as auxiliary storage to help you solve this problem.

For example, if two vectors v1 and v2 had the following values:

v1 = {3, 7, 3, -1, 2, 3, 7, 2, 15, 15}
v2 = {-5, 15, 2, -1, 7, 15, 36}

Your function would return 4 because the elements -1, 2, 7, and 15 occur in both vectors. If the two vectors do not have any elements in common, or if either vector is empty, return 0. Do not modify either vector that is passed in.

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.