[Algorithm] Optional Different Find

xiaoxiao2021-03-06  111

Const int not found = -1;

Int Binsearch (Const Vector & Vec, Int Val)

{

INT low = 0;

INT high = vec.size () -1;

While (low <= high)

{

INT MID (Low High) / 2;

IF (VAL == VEC [MID])

Return MID;

IF (Val

HIGH = MID - 1;

Else

Low = MID 1;

}

Return NOTFOUND;

}

转载请注明原文地址:https://www.9cbs.com/read-103042.html

New Post(0)