Common lookup algorithm

zhaozj2021-02-16  57

//search.h contains all common lookup algorithms

// Lookup function // seqsearch (Const Int Arr [], int first, int laast, int target) Template

// Scan the subscript range first <= i

Return i; // i is the subscript of matching value, or if there is no match, i = last}

// Template function find_last_of () Implementation Template INT FIND_LAST_OF (Const T Arr [], Int First, Int Last, Const T & TARGET {INT i = LAST-1;

// Sweep the subscript range first <= i = first && target! = Arr [i]) I -; IF (i

// Differential search algorithm function BINSearch () Implementation Template INT BINSEARCH (Const T Arr [], INT First, int Last, Const T & Target) {INT MID; / / The subscription T MidValue; / / Used to save Arr [MID] element value

Int Origlast = last; // Save the initial value of Last

While (first

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

New Post(0)