有人能帮我找出我在哪里犯了错误吗?我知道这可能是双重删除或类似的问题。背景是,这是对哈夫曼树的实现,你可以在维基百科上轻松地了解到相关信息。
int main()
{
ifstream input;
input.open("input.txt");
MinPriorityQueue<CharCountNode> heap;
map<char, int> m;
while(input.good())
m[input.get()] += 1;
for( map<char, int>::const_iterator it = m.begin(); it != m.end(); ++it )
heap.enqueue(CharCountNode(it->first, it->second));
while(heap.getSize() > 1)
{
CharCountNode a, b, parent;
a = heap.dequeue();
b = heap.dequeue();
parent = CharCountNode('*', a.getCount() + b.getCount());
parent.left = &a;
parent.right = &b;
heap.enqueue(parent);
}
}
valgrind
并修复它抱怨的第一个问题。重复此过程直到程序正确运行。 - zwol