-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystem.cpp
41 lines (41 loc) · 1016 Bytes
/
FileSystem.cpp
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
#include <iostream>
#include <fstream>
using namespace std;
#include "Huffman.h"
void WriteFile(ofstream *MyFile, struct TNode *T)
{
if (T != NULL)
{
WriteFile(MyFile, T->left);
if (T->left == NULL && T->right == NULL)
{
for (int x = 0; x < T->freq; x++)
{
for (int i = 0; i <= T->len; i++)
{
*MyFile << T->unicodes[i];
}
}
}
WriteFile(MyFile, T->right);
}
}
int main()
{
struct TNode *Start = NULL;
struct TNode *T = NULL;
Insert(&Start, GetTNode('a', 5));
Insert(&Start, GetTNode('r', 7));
Insert(&Start, GetTNode('e', 3));
Insert(&Start, GetTNode('n', 1));
Insert(&Start, GetTNode('t', 1));
Insert(&Start, GetTNode('s', 6));
T = BuildHuffmanntree(&Start);
bool values[100];
int len = -1;
Unicodes(&T, values, len);
ofstream MyFile("encoded");
WriteFile(&MyFile, T);
MyFile.close();
return 0;
}