Good container for insert-in-order? C++
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 fro开发者_StackOverflownt, 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.
If you need only access the front and back, std::deque
(double-ended queue) fits the bill perfectly.
However, for a Dijkstra algorithm, don't you need a priority queue instead?
If you are using C++ there is a std::priority_queue
container adapter in the <queue>
header file.
精彩评论