/*
The structure of the node is
typedef struct node
{
int freq;
char data;
node * left;
node * right;
}node;
*/
void decode_huff(node * root,string s)
{
char str[50];
int i,j,len;
node *p;
len=s.length();
for(i=0,j=0;i<len;i++){
p=root;
while(p){
if(s[i]=='0'){
p=p->left;
}
else{
p=p->right;
}
if(!p->left&&!p->right){
str[j++]=p->data;
break;
}
else{
i++;
}
}
}
str[j]='\0';
printf("%s\n",str);
}
HackerRank Huffman Decoding(Huffman解码)
最新推荐文章于 2022-02-28 09:55:58 发布