Write a recursive function that determines whether an integer array T1 is included
in block in another array of integers T2. It is advisable to write another recursive function that determines whether an integer array T1 begins (is in block at the beginning of) another integer array T2.
Difficulty level

This exercise is mostly suitable for students
int start_rec(int T1[], int start1, int end1, int T2[], int start2, int end2)
{
if (start1 <= end1 && start2 <= end2)
return (T1[start1] == T2[start2] && start_rec(T1, start1 + 1, end1, T2, start2 + 1, end2));
if (start1 <= end1)
return 0;
return 1;
}
int start(int T1[], int N1, int T2[], int N2)
{
return start_rec(T1, 0, N1 - 1, T2, 0, N2 - 1);
}
int sub_array_rec(int T1[], int N1, int T2[], int start2, int end2)
{
if (start2>end2)
return 0;
if (start_rec(T1, 0, N1 - 1, T2, start2, end2))
return 1;
return sub_array_rec(T1, N1, T2, start2 + 1, end2);
}
int sub_array(int T1[], int N1, int T2[], int N2)
{
return sub_array_rec(T1, N1, T2, 0, N2 - 1);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
