Pergunta

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?

Foi útil?

Solução

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

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

Outras dicas

You can use Iterator to iterate over a queue.

Iterator<Customer> iterator=queue.iterator();
while(iterator.hasNext())
{
    Customer c=iterator.next();
 }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top