Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAM create the function: int subsequence(const string a1[], int n1, const string a2[], int n2); the functions you must write take 4 parameters. array

C++ PROGRAM 

create the function: int subsequence(const string a1[], int n1, const string a2[], int n2);

the functions you must write take 4 parameters. array of strings a1[] and a2[] , and the number of items function will consider in the arrays n1 and n2, starting from the beginning. Basically n1 is the number of interesting elements in a1, and n2 is the number of interesting elements in a2. So when we say "the array", we mean the n elements that the function is aware of. If all n2 elements of a2 appear in a1, consecutively and in the same order, then return the position in a1 where that subsequence begins. If the subsequence appears more than once in a1, return the smallest such beginning position in the array. Return 1 if a1 does not contain a2 as a contiguous subsequence or if n1 or n2 are negative. (Consider a sequence of 0 elements to be a subsequence of any sequence, even one with no elements, starting at position 0.) examples:

string names[10] = { "logan", "reed", "sue", "selina", "bruce", "peter" }; string names1[10] = { "reed", "sue", "selina" }; int t = subsequence(names, 6, names1, 3); // returns 1 string names2[10] = { "logan", "selina" }; int u = subsequence(names, 5, names2, 2); // returns -1 

--------------------------

another example:

string h[7] = { "selina", "reed", "diana", "tony", "", "logan", "peter" };

string e[4] = { "diana", "tony", "", "logan" };

assert(subsequence(h, 7, e, 4) == 2);

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

More Books

Students also viewed these Databases questions

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago