We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidPrintCode(node*node,strings,intindex,structnode*root){if(node==nullptr){return;}index=index+1;if(index>s.length()){return;}// cout<<node->freq;//Leaf node reachedif(node->left==nullptr&&node->right==nullptr){cout<<node->data;node=root;}//Move leftif(s[index]=='0'){PrintCode(node->left,s,index,root);}elseif(s[index]=='1'){PrintCode(node->right,s,index,root);}}voidPrintLeafNode(node*node){if(node==nullptr){return;}if(node->left==nullptr&&node->right==nullptr){cout<<node->data<<" "<<node->freq<<endl;}PrintLeafNode(node->left);PrintLeafNode(node->right);}voiddecode_huff(node*root,strings){//given is root node // we can traverse root node based on the value sPrintCode(root,s,-1,root);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Huffman Decoding
You are viewing a single comment's thread. Return to all comments →