-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTree: Huffman Decoding
More file actions
53 lines (36 loc) · 878 Bytes
/
Copy pathTree: Huffman Decoding
File metadata and controls
53 lines (36 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
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)
{
node *temp=root;
s=s+'\0';
for (int i = 0; s[i] != '\0' ; ) {
// printf("%c",s[i]);
if(s[i]=='0'&&temp->left)
{
temp=temp->left;
if(temp->data=='\0')
i++;
else
printf("%c",temp->data),i++,temp=root;
}
else if(s[i]=='1'&&temp->right)
{
temp=temp->right;
if(temp->data=='\0')
i++;
else
printf("%c",temp->data),i++,temp=root;
}
else
printf("%c",temp->data);
}
}