c++ - Huffman's Data compression filltable and invert code problems -
c++ - Huffman's Data compression filltable and invert code problems -
i began learning huffman's info compression algorithm , need help on next function > filltable() , invertcode()
i don't understand why codetable array needed.
while (n>0){ re-create = re-create * 10 + n %10; n /= 10; }
please help me understand going on part of function , why if n larger 0 divided 10 because alway going greater 0 no matter how many times divided it.
link code: http://www.programminglogic.com/implementing-huffman-coding-in-c/
void filltable(int codetable[], node *tree, int code){ if (tree->letter<27) codetable[(int)tree->letter] = code; else{ filltable(codetable, tree->left, code*10+1); filltable(codetable, tree->right, code*10+2); } return; } void invertcodes(int codetable[],int codetable2[]){ int i, n, copy; (i=0;i<27;i++){ n = codetable[i]; re-create = 0; while (n>0){ re-create = re-create * 10 + n %10; n /= 10; } codetable2[i]=copy; }
** edit **
to create question more clear don't need explanation on huffman encoding , decoding need explanation on how these 2 functions work , why codetables necessary.
n
int. therefore, cut down 0 on time. if n starts @ 302 @ first iteration, reduced 30 after first n /= 10;
. @ end of sec iteration of while loop, reduced 3. @ end of 4th iteration, equal 0 ( int 4 / int 10 = int 0 ).
it integer math. no decimal bits extend infinity.
c++ compression huffman-coding
Comments
Post a Comment