2.1.17.8.11 ocmath_is_monotonic


Description

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.

Syntax

int ocmath_is_monotonic( const double * pX, uint nSize, bool bIsStrict = true )

Parameters

pX
[input] pointer to source data
nSize
[input] size of vector
bIsStrict
[input] should be strictly monotonic or not
true is strictly monotonic
false is not

Return

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.

Examples

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.
}

Remark

See Also

Header to Include

origin.h

Reference