Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Find Element Index | Algorithms
C++ STL Containers and Algorithms

bookChallenge: 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::find algorithm to perform the search.
  • Return the zero-based index of the found element.
  • Return -1 if the value is not present in the vector.

Lösning

solution.cpp

solution.cpp

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

close

Awesome!

Completion rate improved to 6.67

bookChallenge: 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::find algorithm to perform the search.
  • Return the zero-based index of the found element.
  • Return -1 if the value is not present in the vector.

Lösning

solution.cpp

solution.cpp

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2
single

single

some-alt