forked from rohitthapliyal2000/Competitive-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree-Huffman_Decoding.cpp
More file actions
52 lines (45 loc) · 883 Bytes
/
Tree-Huffman_Decoding.cpp
File metadata and controls
52 lines (45 loc) · 883 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
/*
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)
{
int length = s.size() , i = 0;
node *temp = root;
while(length >= 0)
{
char check = s.at(i);
if(check == '1')
{
temp = temp -> right;
if(temp -> data == '\0')
{
}
else
{
cout << temp -> data;
temp = root;
}
}
else
{
temp = temp -> left;
if(temp -> data == '\0')
{
}
else
{
cout << temp -> data;
temp = root;
}
}
length--;
i++;
}
}