-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTree.h
More file actions
40 lines (30 loc) · 909 Bytes
/
BinaryTree.h
File metadata and controls
40 lines (30 loc) · 909 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
#pragma once
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <iterator>
struct Node {
char data;
int frequency;
std::string huffmanCode;
Node* left;
Node* right;
Node(char _data, int _frequency) : data(_data), frequency(_frequency), left(NULL), right(NULL) {}
};
class BinaryTree {
public:
Node* root = new Node('\0',-1);
// writes tree into file with preorder traversal
void writeToFile(Node* root);
// prints tree
void printTree(Node* root, int space);
// creates huffman codes of nodes
void createHufmannCodes(Node* root,std::string code);
// creates tree
void createTree(std::vector<Node> nodes);
// encodes string add huffman codes to output
void encode(Node* root, char c, std::string& output);
// decodes codes ang print real message
void decode(Node* root, std::string code, std::string& output);
};