Question: Program Specification The goal of this problem is to write the findConsecutiveDup function that, given an array, recursively finds the index of the first of

Program Specification

The goal of this problem is to write the findConsecutiveDup function that, given an array, recursively finds the index of the first of 2 consecutive values that are equal to each other (duplicates).

  • If there are more than 1 set of consecutive duplicates the function should return the index of the first set (smallest index).

For example, running the findConsecutiveDup function on the array

10 9 8 12 12 10 10 9 12 12 

would return index 3, since the first consecutive duplicates found are the pair of 12's and the first 12 of that pair is at index 3.

You must do this recursively. If you use any type of loop, you will lose a large number of points on this problem. Your solution should be O(n), where n is the size of the array. However, less efficient solutions can still receive partial credit.

main.cpp

#include

using namespace std;

int findConsecutiveDup(int arr[], int size) { // TODO: Implement me }

int main() { int test0[] = { }; int test1[] = { 1 }; int test2[] = { 2, 3 }; int test3[] = { 2, 2 }; int test4[] = { -1, -1, -3, -3 }; int test5[] = { 0, 0, 0, 0, 0, 0 }; int test6[] = { -1, -2, -3, -4, 1, 2, 3, 4, 4 }; int test7[] = { 0, -1, -2, -3, -4, 3, 4, 0 }; int test8[] = { 0, 2, 1, 1, 2, 0, 0, 1 };

cout << "Enter a test case #: "; int testCase; cin >> testCase; cout << endl;

cout << "Test #" << testCase << " Output: "; if (testCase == 0) { cout << findConsecutiveDup(test0, 0) << endl; } else if (testCase == 1) { cout << findConsecutiveDup(test1, 1) << endl; } else if (testCase == 2) { cout << findConsecutiveDup(test2, 2) << endl; } else if (testCase == 3) { cout << findConsecutiveDup(test3, 2) << endl; } else if (testCase == 4) { cout << findConsecutiveDup(test4, 4) << endl; } else if (testCase == 5) { cout << findConsecutiveDup(test5, 6) << endl; } else if (testCase == 6) { cout << findConsecutiveDup(test6, 9) << endl; } else if (testCase == 7) { cout << findConsecutiveDup(test7, 8) << endl; } else if (testCase == 8) { cout << findConsecutiveDup(test8, 8) << endl; } }

ICE:Zybook C++

Please answer this question within 1 hour.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!