Osio 1. Luku 4
single
Challenge: Traverse and Sum Elements
Pyyhkäise näyttääksesi valikon
Tehtävä
Swipe to start coding
Write a function that traverses a container using iterators and returns the sum of all elements.
- The function signature must be
int sum_elements(const std::list<int>& numbers);. - Start iteration at
numbers.begin()and stop when the iterator equalsnumbers.end(). - Use
++itto move the iterator forward. - Only dereference the iterator when
it != numbers.end(). - Do not use
size(),empty(), or indices. - Do not use ranged-for loops or algorithms like
std::accumulate. - The function should return the sum of all elements in the list.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 1. Luku 4
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme