CowEatsGrass - 1 year ago 102

C++ Question

Suppose I have the following declarations:

`int arr[5] = {1,10,9,28,3};`

int low = 0;

int high = 4;

int largest = findLargest(ar, low, high);

I am suppose to write a "findLargest" function using recursion, and this is what I got

`int findLargest(int arr[], int low, int high)`

{

if (low == high)

return arr[low];

return max(arr[low], findLargest(arr, low+1, high));

}

The output was

`28`

`>`

`<`

`==`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The recursion is using the `std::max`

function, which uses `operator>`

. The maximum of the subarray `[a;b]`

is the maximum between `a`

and the maximum of the subarray `[a + 1;b]`

(Which is `a`

if `a = b`

).

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**