how to allocate x number of queues?
I'm trying to write a a program that simulates a multi queues, multi server such as a grocery line at the grocery store.
The user will enter the desired number of queue/server pair.
how would i write this? I mean, I can have 3 - 4 different queue stacks as default, but I'm not sure how to do it if the user actually chooses the number of queues/stacks.
Any help would be greatly appreciated!
here is the link to the project if my english suck.
http://web.stcloudstate.edu/bajulstrom/cs301/projects/p6s09.html
homeryansta
Junior Poster in Training
87 posts since Jan 2009
Reputation Points: 46
Solved Threads: 1
Try something like this:
typedef int Data;
typedef queue<Data> Queue;
vector<Queue> v;
for (int i = 0; i < nQueues; ++i)
v.push_back (Queue());
for (int i = 0; i < nQueues; ++i)
for (int j = 0; j < 5; ++j) // some data
v[i].push (j);
I don't understand templates very well, but what I'm getting from this is:
for (int i = 0; i < nQueues; ++i)
v.push_back (Queue());
allocates each queue
for (int i = 0; i < nQueues; ++i)
for (int j = 0; j < 5; ++j) // some data
v[i].push (j);
throws junk into each queue right?
homeryansta
Junior Poster in Training
87 posts since Jan 2009
Reputation Points: 46
Solved Threads: 1
Yes. I threw some ints into it to show how to access it, but you can make Data whatever you need.
thanks, i'll read up more on vectors since I don't understand it. If i run into any more trouble, you'll see me back here :).
homeryansta
Junior Poster in Training
87 posts since Jan 2009
Reputation Points: 46
Solved Threads: 1
ok, back with more questions.
what is push_back?
I want to say it is a function, but not certain.
homeryansta
Junior Poster in Training
87 posts since Jan 2009
Reputation Points: 46
Solved Threads: 1
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
thanks everyone, I didn't end up using push_back, but I sure did use vectors!! strange thing is that I never learned vectors in my intro to computer science class. I wonder why? Anyone else have the same experience?
homeryansta
Junior Poster in Training
87 posts since Jan 2009
Reputation Points: 46
Solved Threads: 1