5.2哈夫曼树——哈夫曼树与哈夫曼编码
#include <stdio.h> #include <stdlib.h> struct TreeNode{ int Weight; HuffmanTree Left, Right; }; HuffmanTree Huffman(MinHeap H) { int i; HuffmanTree T; for( i = 1; i < H->ESize; i++){ T = malloc(sizeof(struct TreeNode)); T->Left = DeleteMin(H); T->Right = DeleteMin(H); T->Weight = T->Left->Weight + T->Right->Weight; Insert(H, T); } T = DeleteMin(H) return T; }