Question: 2 . Iterating through a List Consider the following program: This program accepts a sentence, one word at a time, and adds each word to

2. Iterating through a List
Consider the following program:
This program accepts a sentence, one word at a time, and adds each word to the end
of the vector. Then, using two iterators for the vector, prints out the words in the
sentence both in correct order and then reverse order. Type in the program as
Lab10A.cpp, compile, and run for yourself to verify its functionality.
CSCE 1045 Lab 10
2
While a vector defines a dynamic array, a list provides an unsorted doubly linked
list. Here are a few points about the STL list container:
It supports a dynamic bidirectional linear list.
Unlike a C++ array, the objects in the list container cannot be accessed directly
(i.e., using a subscript).
It is defined as a template class, meaning that it can be customized to hold objects
of any type.
It behaves like an unsorted list (i.e., the order of the list is not maintained).
In order to use the list, you must include the library.
One of the remarkable properties of C++ and the Standard Template Library is that
you can use identical code with several container types, just by changing the type. For
this lab component, change the type of your container, including the library, from
vector to list, without changing any of the functional code. This means that you
will change the include directive from to and then change your
code anywhere that it has vector to list. Thats it!! Your program should compile
and run without any functional changes other than changing the container type.

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!