From the course: C++ Templates and the STL

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

List

List

- [Instructor] The List is a sequence container like a vector but optimized for rapid insert and delete operations. Lists do not support random access. Here I have a working copy of list.cpp from chapter two of the exercise files, and you'll notice we have the template function for printing a list and our message functions. Again, these are just for convenience and to keep the code, in main, free of the clutter of these repeating patterns. Here, we initialize the list using the template syntax, so this is a list of integers, and it's initialized with the Initializer List, which is available beginning in C++ 11, and it's a very convenient way to initialize these containers. We print the value of it and then we print messages for size, front, and back. When I build and run, you'll see these here. There we print the list and size: 10, front: 1, back: 10. This should all be familiar from the vector. We can use push back to put an element on the back, and here we have the 47 on the back of…

Contents