c++ - Decoding Huffman Tree -


I am implementing a function that takes a tree and an encoded string instance:

  decode (* halffantry, "10010101010")  

I want to return the function, encoded string for the input related to input, the Huffman tree input.

I still have the code:

  string decode (nodeprint root, string encoded_st) {string temp = ""; (Int i = 0; i & lt; encoded_strateged.) (I ++) {if (root-> is_leaf () == true) {temp [i] = root-> gt; // cout & lt; & Lt; Root- & gt; Letter; } If (root-> left! = Null) {encoded_str. } If (root-> right! = Null) {}} return temporary; }  

I have a problem in implementing when neither left or right tap is taken, that is, when I have to move on to the next node.

Any thoughts?

Edit:

  string decode (nodeprint root, string encoded_st) {string temp = ""; Int i; (I = 0; i & lt; encoded_strated) for; I ++) {if (root == NULL} {cout < & Lt; "Error in string" & lt; & Lt; Endl; Return temporary; // court & lt; & Lt; Root- & gt; Letter; } Temp [i] = root- & gt; Letter; If (encoded_tr [i] == '0') {root = root-> Left; } And {root = root-> right; }} For // (Inti = 0; I   

The following can help:

  String decode (NodePtr root, string encoded_st) {string res = ""; NodePtr node = Route; For (int i = 0; i! = Encoded_str.size (); ++ i) {If (encoded_tr [i] == '0') {// left child node = node-> Left; } Else {// rigth child assert (encoded_str [i] == '1'); Node = node-> right; } If (node-> is_leaf () == true) {res + = node-> gt; Node = root; }} Return Ridge; }  

Comments