Question: C++ Suppose you had a std::vector called numbers. Implement a classic for loop so, not a range-based for loop that uses an iterator to determine

C++

Suppose you had a std::vector called numbers. Implement a classic for loop so, not a range-based for loop that uses an iterator to determine the sum of the integers in the vector. Use only the iterator to obtain the various integers in the vector.

Now suppose you instead had a std::list called numbers. Similarly, implement a classic for loop that uses an iterator to determine the sum of the integers in the list. How did your loop look different than the one you wrote for the std::vector? If it looked different, is there a way to rewrite it so that it would be identical in both cases? If so, make the adjustment so they're identical; if not, explain why they can't be made identical.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!