Returns the absolute value of the difference between the maximum value of the left and right half of an array

#include<iostream>
#include<limits.h> //Get the minimum value
#include<algorithm> //max,min header file
int maxABS1(int* arr, int l){ //Array parameter transfer all the array name and size Pass in to avoid degenerate
    int MAX = INT_MIN;
    for(int i = 0; i < l; i++){ //boundary condition
        MAX = std::max(arr[i], MAX); //need using namespace std
    }
    return MAX - std::min(arr[0], arr[l - 1]);
}

int main(){
    int arr[]={2, 7, 3, 1, 1};
    int ABS = maxABS(arr , sizeof(arr)/sizeof(int));
    std::cout<<ABS <<std::endl;
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325564392&siteId=291194637