Priority queue with dynamic item priorities

前端 未结 5 493
抹茶落季
抹茶落季 2020-12-10 02:21

I need to implement a priority queue where the priority of an item in the queue can change and the queue adjusts itself so that items are always removed in the correct order

5条回答
  •  盖世英雄少女心
    2020-12-10 03:01

    Google has a number of answers for you, including an implementation of one in Java.

    However, this sounds like something that would be a homework problem, so if it is, I'd suggest trying to work through the ideas yourself first, then potentially referencing someone else's implementation if you get stuck somewhere and need a pointer in the right direction. That way, you're less likely to be "biased" towards the precise coding method used by the other programmer and more likely to understand why each piece of code is included and how it works. Sometimes it can be a little too tempting to do the paraphrasing equivalent of "copy and paste".

提交回复
热议问题