In this problem, we say that a vector with integer numbers @v[0..@@]@ is unimodal if , and there exists an index such that and satisfying:
@v[0]@ @v[@@]@ @v[@@]@, and
@v[@@]@ @v[@@]@ @v[@@]@ @v[@@]@.
For instance, the vector @[0, 2, 5, 7, 6, 5, 4, 3, 1]@ is unimodal (with ).
Note that vectors with different elements are unimodal. In general, note that any strictly increasing vector is also unimodal (and in all cases ), and analogously, any strictly decreasing vector is also unimodal (and then ).
Implement an efficient function
bool search(int x, const vector<int>& v);
such that, given an integer number @x@ and a unimodal vector @v@, returns true if @x@ appears in @v@, and false otherwise. You can use and implement auxiliary functions if you need them.
The vector @v@ is unimodal.
You only need to submit the required procedure; your main program will be ignored.