-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuffman.h
More file actions
53 lines (44 loc) · 1.15 KB
/
Huffman.h
File metadata and controls
53 lines (44 loc) · 1.15 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
51
52
53
#include<iostream>
#include<queue>
#include<cstring>
#include<map>
#include<fstream>
using namespace std;
class Huffman{
char* data_st;
char* data_end;
int data_size;
char* Encode=new char[1000000];
const int maxn=10000;
// int* vis=new int[maxn]{};
// string* dictionary_data_to_code=new string[maxn]{};
// map<string,char>dictionary_code_to_data;
map<char,int>vis;
map<string,char>dictionary_code_to_data;
map<char,string>dictionary_data_to_code;
string code_res;
struct node{
node* lson;
node* rson;
char data;
int freq;
node(node* x,node* y,char z,int f){
this->lson=x;
this->rson=y;
this->data=z;
this->freq=f;
};
bool operator <(const node* x)const {
return this->freq<x->freq;
}
};
node* root;
priority_queue<node*> q;
public:
Huffman(char* dt_st,char* dt_end);
void init();
void build_tree();
void build_code(node* x,string code);
string encode();
pair<char*,int> decode(string code);
};