priority queue with limited space: looking for a good algorithm

后端 未结 8 1648
旧巷少年郎
旧巷少年郎 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:33

    If you construct an STL priority queue at the maximum size (perhaps from a vector initialized with placeholders), and then check the size before inserting (removing an item if necessary beforehand) you'll never have dynamic allocation during insert operations. The STL implementation is quite efficient.

提交回复
热议问题