Stl queue priority based on lower value
I have a problem with the stl priority queue. I want to have a priority queue in ascending order that is decremented by default. Is there a way to do this in a priority queue.
And what is the complexity of constructing a stl priority queue.If I am using quicksort on an array which takes O (nlgn), its complexity is similar to using a priority queue ???
Plz someone ans.Advanced thanx.
a source to share
Use another comparator as the third template argument std::priority_queue
.
priority_queue is a container adapter that works in whatever order you define. Insertion performance is equal to the operation std::push_heap
and takes logarithmic time. Thus, the complexity of the sort after all insertions is not equal. If you insert a fixed amount and then work with a queue vector
, one sort
might be more efficient.
a source to share
-
priority_queue
have template parameters that define the type of container and the comparison to use for the order. The default is comparisonless<T>
; to get the opposite order, usepriority_queue<T, vector<T>, greater<T>>
. -
Inserting into a priority queue takes logarithmic time, so building a queue of elements
N
hasO(N logN)
the same complexity as creating and sorting a vector. But once created, insertion into the priority queue is still logarithmic, and insertion into a sorted vector is linear.
a source to share