문제

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