From e0245db4985efdbf9b96ca5e3ee58005b90306b3 Mon Sep 17 00:00:00 2001 From: James Bowes Date: Thu, 6 Sep 2012 11:00:11 -0300 Subject: [PATCH] huffman: put smaller weight on the left to match the docs --- huffman.c | 4 ++-- huffman.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/huffman.c b/huffman.c index 6e49e97..43e7019 100644 --- a/huffman.c +++ b/huffman.c @@ -63,8 +63,8 @@ huffman_build_tree(void **values, int count) nodes[tree1] = malloc (sizeof (struct huffman_node)); nodes[tree1]->weight = tmp->weight + nodes[tree2]->weight; nodes[tree1]->value = NULL; - nodes[tree1]->left = nodes[tree2]; - nodes[tree1]->right = tmp; + nodes[tree1]->left = tmp; + nodes[tree1]->right = nodes[tree2]; nodes[tree2]->weight = -1; } diff --git a/huffman.rb b/huffman.rb index 2ddcd65..4f6f9e2 100644 --- a/huffman.rb +++ b/huffman.rb @@ -75,8 +75,8 @@ class NodeQueue end def merge_nodes(node1, node2) - right = node1 - left = node2 + left = node1 + right = node2 node = HuffNode.new(:weight => left.weight + right.weight, :left => left, :right => right) left.parent = right.parent = node node