hi...i have made use ofthe priority queue provided by stl....
the default one in max heap.... but i require minheap....how do i do tat....
Printable View
hi...i have made use ofthe priority queue provided by stl....
the default one in max heap.... but i require minheap....how do i do tat....
You just reverse the comparison predicate for the queue. The default predicate is std::less<T>. If you want it reversed, you need std::greater<T>, i.e. if the priority queue you have now is
then the reverse one isCode:std::priority_queue<int>
Unfortunately, the way the arguments to priority_queue work, you have to specify all arguments if you want to replace the predicate.Code:std::priority_queue< int, std::vector<int>, std::greater<int> >
thanks....:
q.pop() pops out the top elemnt...may i know wat fn returns the top elemnt....
yup its q.top() ...am i right
can i insert another set of values in the priority queue....
like wat we do in prim's algo... associating key with vertices
both key and vertices stored....
or shud i maintain seprte queue for vertices and its key
You can insert pairs and write a custom comparison predicate that compares keys.