-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
68 lines (48 loc) · 2.14 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "main.hpp"
int main(void)
{
std::cout << "\n*** START ROUTINE ***" << std::endl;
ItemType* dataArr = new ItemType[ ARR_BOUND ];
PriorityQueue<NodeType> pq;
std::string filename = fetchFilename();
std::cout << "\n*** Phase One: Load Data Array ***\n" << std::endl;
wait();
loadArr(dataArr, filename);
printArr(dataArr);
std::cout << "\n*** Phase Two: Populate Priority Queue Linked List ***\n" << std::endl;
wait();
// Insert nodes into Priority Queue
for (unsigned int i = 0; i < ARR_BOUND; i++)
if ( dataArr[i].weight )
pq.push(newNode(dataArr[ i ].ascii, dataArr[ i ].weight, nullptr, nullptr));
// Print Priority Queue Contents
pq.print();
std::cout << "\n*** Phase Three: Build Huffman Tree ***\n" << std::endl;
wait();
// Build Huffman Tree
pq.buildHuffTree();
std::cout << "\n*** Phase Four: Encode ASCII Values ***\n" << std::endl;
wait();
std::cout << "*** ASCII Huffman Encodings ***" << std::endl;
std::cout << '#' << std::setw(100) << std::setfill('#') << '#' << std::endl;
std::cout << " ASCII | ENCODING" << std::endl;
std::cout << "*---------------------------------------*" << std::endl;
// Encode ASCII values
for (unsigned int i = 0; i < ARR_BOUND; i++)
if ( dataArr[i].weight )
pq.encode(dataArr[ i ].ascii);
std::cout << '#' << std::setw(100) << std::setfill('#') << '#' << std::endl;
std::cout << "\n*** Phase Five: Decode ASCII Huffman Encodings ***\n" << std::endl;
wait();
std::cout << "*** Decoded Strings ***" << std::endl;
std::cout << '#' << std::setw(100) << std::setfill('#') << '#' << std::endl;
std::cout << "*---------------------------------------*" << std::endl;
// Decode ASCII values
for ( auto str : pq.encodings )
pq.decode( str );
std::cout << "*---------------------------------------*" << std::endl;
std::cout << '#' << std::setw(100) << std::setfill('#') << '#' << std::endl;
delete [] dataArr;
std::cout << "\n*** END ROUTINE ***" << std::endl;
return 0;
}