C++ priority_queue Example
LeetCode Top K Frequent Words need to use STL priority_queue to solve the problem.
There are two ways to implement the priority_queue compare function of customized type.
Overload Operator
Define a struct Cmp and overload operator ():
lambda Function
It would be simpler to implement the compare function using lambda. No extra struct is needed:
