-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (35 loc) · 883 Bytes
/
main.cpp
File metadata and controls
36 lines (35 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
#include <iostream>
#include "encode.hpp"
#include <queue>
#include <functional>
#include <vector>
#include "input.hpp"
int main(void) {
std::priority_queue<Node*, std::vector<Node*>, CompareNode > p;
int characters[256] = {};
std::string encodings[256] = {};
readDocument("test.txt", characters);
for (int x = 0; x< 256; x++) {
if (characters[x] == 0) {
continue;
}
p.push(new Node(characters[x], x));
}
//std::cout << p.top()->getCharacter() << '\n';
while (p.size() > 1) {
Node* left = p.top();
p.pop();
Node* right = p.top();
p.pop();
Node* tree = new Node(left->getCount() + right->getCount());
tree->setLeft(left);
tree->setRight(right);
p.push(tree);
}
Node* tree = p.top();
p.pop();
tree->fillCode(encodings);
compress("../csf/hw7/gcc.trace", "out.txt" , encodings);
delete tree;
return 0;
}