queues

I have a queue which represents people waiting in line at a bank. There is also priority queue who has a list of events which contain arrival times and and transaction times. If a teller is available, the first event (customer) gets popped, his departure time is calculated, a new departure event is created and pushed into the priority queue. The next 2 events (customers) read in from the priority queue have to wait in line, because the first customer is still at the teller, so they get pushed into the queue. All my code is working here.

Now, I need to figure out how long each customer waits in line, and compute an average. The math is simple but I am not sure how to work it out in this scenario and translate to c++ code. The first customer will have zero wait time since he is first in. Then, each customer after that will be: wait = (previous customers departure) - (current customers transaction time).

Any suggestions on how to go about this?


> Now, I need to figure out how long each customer waits in line, and compute an average.
Isn't that just the average of all
cust.transaction_start_time - cust.arrival_time

That is correct. cust.transaction_start_time is equal to previous customers departure time. When someone leaves the teller the next person can start.

I can't do it on one line though. When a departure is processed the next customer is not available yet. I have to follow data that is organized in pseudocode. I start to get lost when trying to get abstract data from different functions to communicate together.

Edit:
wait = (previous customers departure) - (current customers arrival time).
Last edited on
Topic archived. No new replies allowed.