Haxman code original code

xiaoxiao2021-03-06  154

#define INT_MAX 10000 # define ENCODING_LENGTH 1000 # include "stdio.h" #include "string.h" #include "malloc.h" typedef enum {none, left_child, right_child} Which; // mark is left child or right child typedef char elemtype; typedef struct TNode {elemtype letter; int weight; int parent; Which sigh; char * code;} HTNode, * HuffmanTree; int n; char coding [50]; // code storage char str [ENCODING_LENGTH]; // Save the sentence void inittreenode (huffmantree & ht) {// initially n-nodes, then Mn Nienji blank INT i; int W; char C; int m = 2 * n-1; Huffmantree P; HT = (Huffmantree) malloc ((m) * sizeof (htnode)); Printf ("Input% D Database Letter and Weight", N); P = Ht; GetChar (); for (i = 1; i <= n; i ) {scanf ("% C% D", & w); p-> code = '/ 0'; p-> letter = C; p-> parent = 0; p-> sigh = none; p- > weight = W; p ; getchar ();} for (; i <= m; i , p ) {p-> code = '/ 0'; p-> letter = ''; p-> parent = 0; P-> sigh = none; p-> weight = 0;}} // init, int end, int * s1, int * S2) {// 0 ~ END, identify two node serial numbers, returns S1, S2INT I; int min1 = int_max; int min2; for (i = 0; i <= end; i ) {// find the smallest Nose serial number IF (HT [i] .parent == 0 && HT [i] .Weight HT [i] .weight) {* S2 = i; min2 = HT [i] .weight;}}} void huffmantreecreat (Huffmantree &)

HT) {// Establish Huffman Tree INT I; INT M = 2 * N-1; INT S1, S2; for (i = N; I ) {SELECT (HT, I-1, & S1, & S2) ; Ht [s1] .parent = i; ht [s2] .parent = i; ht [s1]. Sigh = left_child; ht [s2] .sigh = Right_Child; HT [i] .weight = HT [S1] .weight HT [S2] .Weight;}} void huffmantreecode (huffman) {// huffman decoding INT i; char * temp; temp = (char *) malloc (n * sizeof (char)); TEMP [N-1 ] = '/ 0'; int P; int S; for (i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-127712.html

New Post(0)