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

bookChallenge: Find Element Index

Tehtävä

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.

Ratkaisu

solution.cpp

solution.cpp

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 2
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

What is Markdown and how is it used?

Can you show me some basic Markdown syntax?

What are the main features of Markdown?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Find Element Index

Pyyhkäise näyttääksesi valikon

Tehtävä

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.

Ratkaisu

solution.cpp

solution.cpp

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 2
single

single

some-alt