stl priority queue based on lower value first

前端 未结 6 1862
故里飘歌
故里飘歌 2020-12-18 15:35

I have a problem with stl priority queue.I want to have the priority queue in the increasing order,which is decreasing by default.Is there any way to do this in priority qu

6条回答
  •  死守一世寂寞
    2020-12-18 16:33

    You can use comparator class/struct to achieve the same in priority queue.

    class CompareHeight 
    { 
        public:
            bool operator()(int &p1, int &p2) 
            {
                return p1 > p2; 
            } 
    };
    

    Now declare the priority queue as

    priority_queue, CompareHeight> pq;
    

提交回复
热议问题