• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Is iterator the best way to loop through PriorityQueue

Resolved: Is iterator the best way to loop through PriorityQueue

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I want to loop through a PriorityQueue, and wondering if following iterator() is the best way
I suppose its time complexity would be O(1)?
I don’t care about the queue afterwards, so another way would be to use poll() while !queue.isEmpty() but the time complexity would be O(logn).

Answer:

If you want ordered retrieval of your elements, you must poll/remove elements from the queue; using iterator will not be enough.

If you have better answer, please add a comment about this, thank you!

java priority-queue queue
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Input Focus between two React Components

02/04/2023

Resolved: linq2db throws exception when filtering by nested collection

02/04/2023

Resolved: Table data is coming as empty in React

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.