I still don't have this set up right. I'm trying to simulate five checkout lines in a grocery store. This is what I did, but it isn't quite right:
1 2 3 4 5 6 7
vector< deque<int> > line; //initialize a vector of 5 deques
//initial setup for each line
for (int i = 0; i < 5; i++)
{
line.push_back( deque<int>(i) ); //add 5 shopping lines to the vector
}
I can see why this isn't right, but I don't know how to correct it. As I look at this, I have one vector (which corresponds to the grocery store). Inside that vector, I have five deques (which correspond to the five lines in the store).
I should change the first line to this: vector< deque<int> > store;, which would make it more intuitive (to me).
How then, do I initialize the five deques so that they can later be manipulated like this:
1 2 3 4
for (int i = 0; i < 5; i++)
{
line[i].push_back(something);
}
I've got an entire program written on the idea that these lines can be used like in that for loop. Only when I got into testing did I realize that my error went all the way back to how I set this up.
It makes more sense this way: Lines.push_back(deque<int>());
I called the variable Lines because it contains...Lines.
And note that I pushed back a brand new empty double-ended queue, whereas before you were initializing with a starting size of i.
Then to manipulate the deques: Lines[i].deque_function_name(something);
Not really the variable names. I was just using that as a way to make my post more clear and possibly to make my code more intuitive. L B's post gave me what I need (pending testing, of course).