First occurrence P84219


Statement
 

pdf   zip   main.cc

thehtml

Write an efficient function

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

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

Precondition

The vector v 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++