while(count != 25) {
tail = head;
new_node = (binary_node*)malloc(sizeof(binary_node));
while(tail->next != NULL)
tail = tail->next;
tail->next = new_node;
new_node->element.frequency = (p->element.frequency + q->element.frequency);
new_node->LSON = p;
new_node->LSON->RTAG = 0;
new_node->RSON = q;
new_node->RSON->RTAG = 1;
head = new_node;
n = n - 1;
head = q->next;
sort(n, head);
p = head;
q = p->next;
count++;
}
上面的代码应该生成一个霍夫曼树。但是,形成的二叉树是不正确的。所有包含字母的节点都应该是叶子或没有儿子的节点,但一些字母节点仍然有儿子。代码有什么问题?