Question
Question 1: Identify the common elements of two sorted arrays You are given two lists of numbers and are interested in the numbers common to
Question 1: Identify the common elements of two sorted arrays
You are given two lists of numbers and are interested in the numbers common to both lists. A number x is common to list1 = hl0, l1, . . . , lpi and list2 = hm0, m1, . . . , mqi if and only if there exists an 0 ? i ? p and an 0 ? j ? q such that li = x = mj . In this question youre asked to write a C++ function to identify and return the elements common to two lists provided as input. The input lists are represented as arrays of ints in sorted (ascending) order and there are no repeated numbers within any one array. Youre given list1 and its length p, list2 and its length q, and are asked to return the result in out, which can hold at most outcap elements. If there are more than outcap common elements, return only the first outcap of them. Your function should return the number of items now stored in out.
Remember: Each list is sorted in ascending order and no number appears more than once in a list. int get_list_of_common(int list1[], int p, int list2[], int q, int out[], int outcap)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started