0

If we have 2 queues, we can simply use SelectOutPut, if (queue1.size() < queue2.size()) go to Queue1, else go to Queue2.

But what if we have 12 queues? Using only if else will be a nightmare. So what will be our approach?

Note: Going through all the queues through a for loop could be the answer. If it's possible, then how?

Aqeel Tariq
  • 315
  • 1
  • 8

2 Answers2

0

I do not know the purpose of the conditions when you need smaller size or bigger and etc.

You can probably use a PriorityQueue the complexity will be bigger but it will looks cleaner in the code.

How do I use a PriorityQueue?

each time you poll from the PQ you can choose whether the smaller will be first or the bigger ( in size I assume ) and you insert in right after - so it can be used after (if needed).

if you are still want to do this with a loop - please give more details on what you trying to achieve, since its kinda hard to guess

Good Luck !

Eyal Hadad
  • 35
  • 5
0

you can add all the queues into a collection and then do this

Queue queue=top(collection,q->-q.size());
go to queue
Felipe
  • 8,311
  • 2
  • 15
  • 31
  • I made the collection of queues. Now, the code you write, what it is doing and where I should paste it, can you explain it? With source, we can attach only one queue, so how to solve that problem? – Aqeel Tariq Oct 09 '22 at 15:23