First occurrence P84219


Statement
 

pdf   zip   main.cc

Write an efficient function

    int first_occurrence(double x, const vector<double>& v);

that returns the position of the first occurrence of xx in the vector vv. If xx does not belong to vv, return a -1.

Precondition

The vector vv is sorted in nondecreasing order.

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++