I have an assignment that I am working on that has the function outline provided. I am supposed to return the position of the found item if it is found or -1 if not. Here is that outline code:
int linearSearch( const vector<int>& inputVec, int x) {
and I have to fill in the function using the find
algorithm. My understanding is that find
returns an iterator. I'm just not sure how to take that and return an integer that is the position or a -1.
Right now I am trying this on the inside.
auto it = find(inputVec.begin(), inputVec.end(), x);
and I'm not sure where to go from there.