huffman: put smaller weight on the left to match the docs
This commit is contained in:
parent
9ab0b0d2aa
commit
e0245db498
2 changed files with 4 additions and 4 deletions
|
@ -63,8 +63,8 @@ huffman_build_tree(void **values, int count)
|
||||||
nodes[tree1] = malloc (sizeof (struct huffman_node));
|
nodes[tree1] = malloc (sizeof (struct huffman_node));
|
||||||
nodes[tree1]->weight = tmp->weight + nodes[tree2]->weight;
|
nodes[tree1]->weight = tmp->weight + nodes[tree2]->weight;
|
||||||
nodes[tree1]->value = NULL;
|
nodes[tree1]->value = NULL;
|
||||||
nodes[tree1]->left = nodes[tree2];
|
nodes[tree1]->left = tmp;
|
||||||
nodes[tree1]->right = tmp;
|
nodes[tree1]->right = nodes[tree2];
|
||||||
|
|
||||||
nodes[tree2]->weight = -1;
|
nodes[tree2]->weight = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,8 @@ class NodeQueue
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_nodes(node1, node2)
|
def merge_nodes(node1, node2)
|
||||||
right = node1
|
left = node1
|
||||||
left = node2
|
right = node2
|
||||||
node = HuffNode.new(:weight => left.weight + right.weight, :left => left, :right => right)
|
node = HuffNode.new(:weight => left.weight + right.weight, :left => left, :right => right)
|
||||||
left.parent = right.parent = node
|
left.parent = right.parent = node
|
||||||
node
|
node
|
||||||
|
|
Loading…
Reference in a new issue