Huffman coding: Difference between revisions

Line 220:
{
public:
INode* parent;
int f;
 
Line 226 ⟶ 225:
 
protected:
INode(INode* parent, int f) : parent(parent), f(f) {}
};
 
Line 234 ⟶ 233:
INode* children[2];
 
InternalNode(INode* parent, INode* c0, INode* c1) : INode(parent, c0->f + c1->f)
{
children[0] = c0;
children[1] = c1;
 
c0->parent = this;
c1->parent = this;
}
~InternalNode()
Line 254 ⟶ 250:
char c;
 
LeafNode(INode* parent, int f, char c) : INode(parent, f), c(c)
{}
};
Line 271 ⟶ 267:
{
if(frequencies[i] != 0)
trees.push(new LeafNode(NULL, frequencies[i], (char)i));
}
while (trees.size() > 1)
Line 281 ⟶ 277:
trees.pop();
 
INode* parent = new InternalNode(NULL, childR, childL);
trees.push(parent);
}
Anonymous user