3

Hi I was wondering what the best container for inserting elements in order in? A map I think is unnecessary since I am just going to be accessing the element at the front, popping it and then inserting more elements (I'm implementing a pathfinding algorithm (Dijkstra) with weights)

I could probably have used a list and inserted in order myself, but the inability to bisect (because you start accessing at the front or back) would be hindering to performance.

4

2 回答 2

2

如果您只需要访问正面和背面,std::deque(双端队列)非常适合该法案。

但是,对于 Dijkstra 算法,您不需要优先级队列吗?

于 2011-03-13T08:55:31.403 回答
2

如果您使用的是 C++,则头文件std::priority_queue中有一个容器适配器。<queue>

于 2011-03-13T09:06:07.000 回答