What is the problem?
When I use priority queue of STL, I want to use min heap, so I used like below code.
It works on default option but it is not working on "greater option".
It always arranges like above picture. I don't know totally why this happened.
struct node {
string code;
int fre;
bool operator<(const node& rhs) const {
return fre < rhs.fre;
}
bool operator>(const node& rhs) const {
return fre > rhs.fre;
}
};
std::priority_queue<node, vector<node>, greater<node>> q;
std::map<node,int> huffman_tree;
int main(void)
{
int f;
for (int i = 1; i <= n; i++) {
string c;
std::cin >> c >> f;
node huffman = { c,f };
q.push(huffman);
}
q.pop();
return 0;
}