Pages

Monday, 30 August 2021

Chapter 20 // Exercise 11 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 20 // Exercise 11

Given a list<int> as a (by-reference) parameter, make a vector<double> and copy the elements of the list into it. Verify that the copy was complete and correct. Then print the elements sorted in increasing value.


This one was pretty simple as std::vector has a handy range constructor (since C++98). Basically you give it an iterator to a start and end position in the container and it will copy over those values into the vector. It's a nice one-liner:
vector<double> doubleVector(list.begin(), list.end());

No comments:

Post a Comment