Resistant dichotomic search P33412


Statement
 

pdf   zip   main.cc

html

Write an efficient function

bool resistant_search(double x, const vector<double>& v);

that tells if x belongs to the vector v or not.

Precondition

The vector v is “almost sorted” in nondecreasing order, in the sense that there may be at most a pair of indices i and j such that 0 ≤ i < j < n and V[i] > V[j].

Observation You only need to submit the required procedure; your main program will be ignored.

Information
Author
Salvador Roura
Language
English
Official solutions
C++
User solutions
C++