-2

could anyone please tell me how to write this priority queue (written in C++) using Java

priority_queue< pair< int, Hole >, vector< pair< int, Hole > >, Hole::CompH > moves;

the CompH is a struct:

   struct CompH {
                bool operator()(const pair< int, Hole >& lhs, const pair< int, Hole >& rhs) const
                {
                        return lhs.second.getH() < rhs.second.getH();
                }
        };

I want to understand this part so I can write it in Java, Please. Thanks

3

1 Answer 1

0

The CompH is directly analogous to a java.util.Comparator, and the PQ class itself is java.util.PriorityQueue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.