Write a method named, isOddHigh, that takes as input, any array of integers and it returns true, if
every odd number in the array is greater than all even numbers in the array, otherwise it returns false.
e.g. isOddHigh([9, -6, 2, 5, 4, 7]) will return true; whereas, isOddHigh([7, 2, 5, 8]) and isOddHigh([9, 4, 7,
5, 8]) should return false since 5 is not greater than 8. Also, when isOddHigh(...) is called and the input
argument passed is null or an empty array or an array with no odd number, it should return, false.
step 0: looks like they jacked in some extra requirements at the end that really went first. Return false here if any of the special conditions are found. If not, proceed.
if every odd > all even, then it must be true:
every odd > largest even.
so that begs: step 1: find largest even.
and
step2: loop, check to see if all odd > largest even.
#include <climits>
// return the largest even number in the array
// return INT_MIN if the array is empty or if there are no even numbers
int largest_even_number( constint array[], std::size_t num_elements )
{
// https://en.cppreference.com/w/cpp/header/climitsint largest = INT_MIN ; // smallest possible value that an int can have
for( std::size_t i = 0 ; i < num_elements ; ++i ) // for each position in the array
{
constint number = array[i] ; // get the number at position i
if( number%2 == 0 ) // if it is an even number
{
// if it is greater than the largest seen so far, update largest
if( number > largest ) largest = number ;
}
}
return largest ;
}
// return the smallest odd number in the array
// return INT_MAX if the array is empty or if there are no odd numbers
int smallest_odd_number( constint array[], std::size_t num_elements ) ;
// TO DO: implement this function
// return true if if every odd number in the array is greater than all even numbers in the array
bool isOddHigh( constint array[], std::size_t num_elements ) ;
// TO DO: implement this function
// hint: return false if array == nullptr or if num_elements == 0
// hint: return true if the smallest odd number in the array is greater than
// the largest even number in the array; return false otherwise