Judge if a vector is (strictly) monotonic. Call the function IsOrdered of class NRVec to check the vector in (strictly) ascending(descending) order or not.
int ocmath_is_monotonic( const double * pX, uint nSize, bool bIsStrict = true )
return MONO_INCREASE if data is increasing,
MONO_DECREASE if data is decreasing,
MONO_NOT if not monotonic,
OE_INVALID_SIZE if size is zero
OE_NULL_POINTER if pX is NULL pointer.
EX1
void ocmath_is_monotonic_ex1() { vector vT = {1, 2, 3, 4, 5}; int iRet = ocmath_is_monotonic(vT, vT.GetSize()); if(iRet == MONO_INCREASE) out_str("strictly increasing"); //vT is an increasing monotonice vT[1] = 0; iRet = ocmath_is_monotonic(vT, vT.GetSize()); if(iRet == MONO_NOT) out_str("not strictly monotonic"); //After replace with 0, vT not a monotonic array. }
origin.h