Challenge: Find Element Index
Uppgift
Swipe to start coding
Write a function named findIndex that takes a std::vector<int> and an int value as arguments. Use the std::find algorithm from the Standard Library to search for the value in the vector. If the value is found, return its index; if not, return -1.
- Use the
std::findalgorithm to perform the search. - Return the zero-based index of the found element.
- Return
-1if the value is not present in the vector.
Lösning
solution.cpp
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 2
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 6.67
Challenge: Find Element Index
Svep för att visa menyn
Uppgift
Swipe to start coding
Write a function named findIndex that takes a std::vector<int> and an int value as arguments. Use the std::find algorithm from the Standard Library to search for the value in the vector. If the value is found, return its index; if not, return -1.
- Use the
std::findalgorithm to perform the search. - Return the zero-based index of the found element.
- Return
-1if the value is not present in the vector.
Lösning
solution.cpp
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 2
single