Question: In C + + implement the following function: bool findAll ( int nums [ ] , int length, int target, int &firstIndex, int &lastIndex )

In C++ implement the following function:
bool findAll(int nums[], int length, int target, int &firstIndex, int &lastIndex);
The function takes a sorted array nums (sorted in ascending order) and returns true if the target is found and false otherwise. Also, if the target is found, the function sets firstIndex and lastIndex to the indexes of the first and last occurrences.
If the target =3 and nums (of length 5) contains the values {3,3,3,7,9} then a call to findAll will return true, having set firstIndex to 0 and lastIndex to 2. On the other hand, if target =7 with the same array, then the return value will still be true, but both firstIndex and lastIndex will be set to 3. Finally if the target is 8 with the original array, then the return value will be false, and firstIndex and lastIndex won't be assigned any values (leave them unchanged).
Please explain each step please thank you.

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!