Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Students also viewed these Databases questions

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Know how productivity improvements impact quality and value.

Answered: 1 week ago

Question

Recommend the key methods to improve service productivity.

Answered: 1 week ago