What data structure to use when I need to
With Java's PriorityQueue, I can't access a node directly by its name/id property can I?
I was thinking along the lines of use a priority queue, plus a TreeMap so I can search by name in log(n) time, then modify the priority. But I doubt the Queue will know of that? In that case, I need to remove and re-add the node? Is that worth the overhead? What complexity is it to remove/re-add a node?
In that case, I need to remove and re-add the node?
Yes.
Is that worth the overhead?
That depends on your requirements. Only you know that.
What complexity is it to remove/re-add a node?
Insert and remove from a PriorityQueue is O(log n).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.