Construction and coding and decoding of the Harman tree
/*
* Implementation process: the user first constructs the User-Defined tree using the HuffmanTree () function, and then * starts from the bottom up (that is, starting from the node where the array serial number is zero) in the main () function) it is determined from the above layer. If it is on the left side of * parent node, it is set to 0. If it is on the right side, it is set to 1. Finally, the generated encoding is output. * ------------------------------------------------------------------------ */# Include
# Include
# Include
Const int MAXBIT = 100; const int MAXVALUE = 10000; const int MAXLEAF = 30; const int MAXNODE = MAXLEAF * 2-1; typedef struct {int bit [MAXBIT]; int start;} HCodeType; // The encoding structure typedef struct {int weight; int parent; int lchild; int rchild; int value;} HNodeType; // node struct // input and initialize void node_input (HNodeType HuffNode [], const int & n) {int I; for (I = 0; I