You might want to check out "The C++ Standard Library"(Josuttis), Chapter 5, which has very simple explanations and simple examples of how to use the STL containers, e.g. vectors, lists, maps. Daved and others have recommended the book, and I just purchased it. The rest of the book covers the topics introduced in chapter 5 in more detail. The STL containers provide numerous facilities that allow you to traverse the containers, sort them, copy them, randomize them, and modify them. It's all quite easy. As far as I know, you can nest your containers as deep as you want: you could have a list of deques, with each deque being a collection of lists, with each list being a collection of vectors.
Originally Posted by Mariano L Gappa
All the STL containers can be expanded or contracted to any size. Their size has no bearing on their type.
Yet the question remains...Do you know if I can nest a STL deque inside a STL list, given that the deque's size would be unknown?
Here is a simple example of some of the things you can do:
If you get a bunch of warnings when using the STL, it's because some of the names in the STL are longer than 255 characters and some compilers can't handle that.
#include <list> //list<deque<int> >, list<deque<int> >::iterator
#include <deque> //deque<int>, deque<int>::iterator, deque<int>::const_iterator
#include <algorithm> //random_shuffle()
#include <functional> //greater<int>
using namespace std;
void displayDeque(const deque<int>& aDeque);
//Create and fill a deque:
for(int i = 1; i <= 20; i++)
//Randomize a range in the deque:
//Sort a range in the deque:
//switch the sort from the default STL less() function
//to the STL greater() function:
sort(myDeque.begin(), myDeque.end(), greater<int>());
//Find a value:
pos = find(myDeque.begin(), myDeque.end(), 5);
//Shuffle all the values after the found value:
//Create a list of deques:
list<deque<int> > myList; //careful: need a space between the '> >'
myList.push_back(myDeque); //myDeque contains 20 ints
myList.push_back(myDeque2);//myDeque2 contains 3 ints
displayDeque(*myList.begin()); //displays the first deque in the list
list<deque<int> >::iterator k = myList.begin();
displayDeque(*(++k)); //displays the next deque in the list.
//careful: you can't dereference end(); it doesn't
//point to the last element--it's beyond the last element
//Add elements to a deque in the list:
void displayDeque(const deque<int>& aDeque)
deque<int>::const_iterator i = aDeque.begin();
deque<int>::const_iterator end = aDeque.end();
while(i != end)