-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHuffmanTree.cpp
More file actions
50 lines (45 loc) · 1.05 KB
/
HuffmanTree.cpp
File metadata and controls
50 lines (45 loc) · 1.05 KB
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
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include "HCTree.h"
using namespace std;
void line_table()
{
for (int i = 0; i < 30; i++)
cout << "-";
}
void double_endl()
{
std::cout << endl << endl;
}
int main()
{
HCTree h;
string str, encodedString, decodedString,
sen = "[*] ENTER SENTENCE: ",
charfreq = "[*] CHARACTER & FREQUENCIES:",
encodemsg = "[*] ENCODED DATA: ",
decodemsg = "[*] DECODED DATA: ";
cout << sen;
getline(cin, str);
cout << endl;
h.calcFreq(str, str.length());
h.HuffmanCodes(str.length());
cout << charfreq << endl;
line_table();
cout << endl;
for (auto v = h.codes.begin(); v != h.codes.end(); v++)
{
cout << v->first << ' ' << v->second << endl;
}
for (auto i : str)
{
encodedString += h.codes[i];
}
line_table();
double_endl();
cout << encodemsg << encodedString << endl << endl;
decodedString = h.decode(encodedString);
cout << decodemsg << decodedString << endl;
}