سؤال

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?

هل كانت مفيدة؟

المحلول

If you need to do a for each type iteration, you can go through PriorityQueue<Customer> using

for (Customer c : queue) {
    ...
} 

نصائح أخرى

You can use Iterator to iterate over a queue.

Iterator<Customer> iterator=queue.iterator();
while(iterator.hasNext())
{
    Customer c=iterator.next();
 }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top