Reputation: 71
I've been asked to simulate the events for a store with one counter in java using a priority queue. Where a person is being served and if someone arrives during this time i increment the number of people in the queue.I figured out that I have to use Comparator but so far it seems like i can only use comparator for sorting and not for queuing and DE-queuing events.
Upvotes: 0
Views: 1913
Reputation: 19855
If you are using a discrete event modeling perspective, you use a priority queue to schedule the sequence of events that drive the system. You can find a tutorial paper on how to do this, along with a Java implementation for a single server queue with exponential interarrival and service times, in the Winter Simulation Conference paper archives.
Upvotes: 2
Reputation: 3709
Problem statement you have mentioned you can implement it using a simple Queue, I could think of following design.
If you are working on collections and you need to sort objects then you need a compartor, but given the problem statement, looks like there is not need for sorting.
Cheers !!
Upvotes: -1