I am writing a C ++ application where it is critical to have an O (1) Dequeue operation for the priority queue, while it is not so important, the complexity of Enqueue (well, if it does not become an n ^ 2 or 2 ^ n course).
At first I used a linked list. It was very good for Dequeue (O (1)), and he had good queue complexity. The only problem was sorting it. Not the fact that using Sorting Sorting, with O (n) complexity, could satisfy my needs. But sorting a linked list is a pain. It was sloooow.
Vector is not good at all. Dequeue will be O (n) to move all elements back. Enqueue will still be O (n), but much faster.
Can you suggest a more efficient method? Thank.
source
share