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

Recommended Answers

All 7 Replies

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);

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?

Yes. I threw some ints into it to show how to access it, but you can make Data whatever you need.

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 :).

ok, back with more questions.

what is push_back?

I want to say it is a function, but not certain.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.