C ++ lookup algorithm

xiaoxiao2021-03-06  104

INT Seqsearch (int Arr [], int Len, int target)

{

??? INT i = 0;

??? While ((i! = len) && (arr [i]! = target))

??? {

??????? i ;

???}

??? IF (i

??? {

??????? RETURN I;

???}

??? ELSE

??? {

??????? Return -1;

???}

}

INT BINSEARCH (int Arr [], int LEN, int target) {??? int low = 0; ??? Int high = len-1; ??? while (low <= high) ??? {??? ???? Int mid = (low high) / 2; ??????? f (arr [mid] == Target) ???????????????????????? RETURN MID; ???????} ??????? Else IF (Arr [MID]> TARGET) ??????? {??????????? HIGH = MID - 1; ???????} ??????? ELSE ??????? {??????????? Low = MID 1; ????? ??} ???} ??? Return -1;}

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

New Post(0)