The function I am trying to write is supposed to be recursive and does the following:
Return the number of ways that all n2 elements of a2 appear in the n1 element array a1 in the same order (though not necessarily consecutively). The empty sequence appears in a sequence of length n1 in 1 way, even if n1 is 0.
For example, if a1 is the 7 element array
"Bart" "Lisa" "Maggie" "Marge" "Lisa" "Maggie" "Homer"
then for this value of a2 the function must return
"Bart" "Marge" "Maggie" 1
"Bart" "Maggie" "Homer" 2
"Marge" "Bart" "Maggie" 0
"Lisa" "Maggie" "Homer" 3
So far, I have written this much:
int countIncludes(const string a1[], int n1, const string a2[], int n2)
{
if (n2 == 0)
return 1;
if (n1 == 0)
return 0;
else
{
if (a1[0] == a2[0])
return countIncludes(a1+1, n1-1, a2+1, n2-1);
else
return countIncludes(a1+1, n1-1, a2, n2);
}
}
But it is incomplete and I know it does not work properly. I need help figuring out how to do this problem--just a method about how to go about this would be extremely helpful.
Thank you so much in advance!