If you need to do a for each
type iteration, you can go through PriorityQueue<Customer>
using
for (Customer c : queue) {
...
}
Question
I have a bank teller simulation program I am writing, using a PriorityQueue(PQ) full of objects of the class type Customer, which has a field priorityNum. When a customer leaves the queue, I need to increment the priorityNum of customers still in the queue.
My question being: How can I go through a PQ and increment a field for the objects?
Solution
If you need to do a for each
type iteration, you can go through PriorityQueue<Customer>
using
for (Customer c : queue) {
...
}
OTHER TIPS
You can use Iterator to iterate over a queue.
Iterator<Customer> iterator=queue.iterator();
while(iterator.hasNext())
{
Customer c=iterator.next();
}