Question: List Iterator Write the method std::string findInList(std::list &myList, int valueToFind) . The method takes a list and a value to find as arguments, creates a

List Iterator

Write the method std::string findInList(std::list &myList, int valueToFind) . The method takes a list and a value to find as arguments, creates a iterator and uses an iterator to traverse the list and return an integer that is the index of the item to be found. Return -1 if the item is not in the list.

Sample Input 1:

4 2 1 2 3 4 

Sample Output 1:

1 

Sample Input 2:

4 2 4 3 2 1

Sample Output 2:

2

Sample Input 3:

3 5 1 2 3

Sample Output 3:

-1

Sample Input 4:

1 1 1

Sample Output 4:

0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!