Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Traverse and Sum Elements | Iterator Fundamentals
/
C++ STL Iterators
Seção 1. Capítulo 4
single

single

bookChallenge: Traverse and Sum Elements

Deslize para mostrar o menu

Tarefa

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 equals numbers.end().
  • Use ++it to 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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt