Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Traverse and Sum Elements | Iterator Fundamentals
C++ STL Iterators
Sección 1. Capítulo 4
single

single

bookChallenge: Traverse and Sum Elements

Desliza para mostrar el menú

Tarea

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.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 4
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt