使用递归在数组中查找最大值

Cow*_*ass 0 c++ recursion

假设我有以下声明:

int arr[5] = {1,10,9,28,3};
int low = 0;
int high = 4; 
int largest = findLargest(ar, low, high);
Run Code Online (Sandbox Code Playgroud)

我想用递归写一个"findLargest"函数,这就是我得到的

 int findLargest(int arr[], int low, int high)
 {      
    if (low == high)
        return arr[low];
    return max(arr[low], findLargest(arr, low+1, high));
 }
Run Code Online (Sandbox Code Playgroud)

输出是28,这是预期的.但是,我真的不明白这个递归函数如何"比较"这些值.(我的意思是我没有看到任何操作符,例如>,<.我看到的唯一操作符是==).那么,这个递归函数如何比较数组中的值?

小智 6

递归使用的std::max函数使用operator<.子阵列的最大值是子阵列[a;b]的最大值a和最大值[a + 1;b](a如果是a = b).