priority queue with limited space: looking for a good algorithm

后端 未结 8 1664
旧巷少年郎
旧巷少年郎 2020-12-06 02:07

This is not a homework.

I\'m using a small \"priority queue\" (implemented as array at the moment) for storing last N items with smallest value. This is a b

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 02:37

    Matters Computational see page 158. The implementation itself is quite well, and you can even tweak it a little without making it less readable. For example, when you compute the left child like:

    int left = i / 2;
    

    You can compute the rightchild like so:

    int right = left + 1;
    

提交回复
热议问题