access the underlying vector of priority_queue in C++

#include
#include

struct MyPriorityQueue: std::priority_queue<int> {
    auto begin() const { return c.begin(); }
    auto end() const { return c.end(); }
    auto operator[](size_type __n)  {return c.operator[](__n);}
};

int main() {
    MyPriorityQueue pq;
    pq.push(0);
    pq.push(1);
    for(auto &v: pq) {
        std::cout << v << std::endl;
    }

    std::cout << pq[0] << " " <<  pq[1] << std::endl;
}

output

1
0
1 0

你可能感兴趣的:(c++,算法,开发语言)