-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint.h
107 lines (88 loc) · 2.09 KB
/
Print.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef __PRINT_H__
#define __PRINT_H__
#include<bits/stdc++.h>
#include "huffman.h"
#include<iostream>
using namespace std;
#define COUNT 10
void huffman::printBinary(UINT code, CHAR code_len)
{
for(unsigned char i=code_len;i>0;i--)
{
unsigned char d = ((code >> (code_len-1)) & 0x01);
cout<<(int)d;
code = code<<1;
}
}
void huffman::print2DUtil_sgh(sgh_node *root, int space)
{
// Base case
if (root == NULL)
return;
// Increase distance between levels
space += COUNT;
// Process right child first
print2DUtil_sgh(root->right, space);
// Print current node after space
// count
cout<<endl;
for (int i = COUNT; i < space; i++)
cout<<" ";
cout<<root->code;
if(root->is_symbol_node)cout<<"("<<(char)root->id<<")";
if(root->is_subtree_root)cout<<"(@)";
cout<<endl;
// Process left child
print2DUtil_sgh(root->left, space);
}
// Wrapper over print2DUtil()
void huffman::print2D_sgh(sgh_node *root)
{
// Pass initial space count as 0
print2DUtil_sgh(root, 0);
}
void huffman::print2DUtil_huffman(huffman_node *root, int space)
{
// Base case
if (root == NULL)
return;
// Increase distance between levels
space += COUNT;
// Process right child first
print2DUtil_huffman(root->right, space);
// Print current node after space
// count
cout<<endl;
for (int i = COUNT; i < space; i++)
cout<<" ";
cout<<root->code<<"\n";
// Process left child
print2DUtil_huffman(root->left, space);
}
// Wrapper over print2DUtil()
void huffman::print2D_huffman(huffman_node *root)
{
// Pass initial space count as 0
print2DUtil_huffman(root, 0);
}
void huffman::printIndexArray()
{
cout<<" PRINTING INDEX ARRAY "<<endl;
int count = 0;
for(auto x:index_array)
{
cout<<"T"<<count<<" [ "<<x.starting_address<<" , "<<x.depth_subtree<<" ] "<<endl;
count++;
}
}
void huffman::printSymbolArray()
{
cout<<" PRINTING SYMBOL ARRAY "<<endl;
int count = 0;
for(auto x:symbol_array)
{
cout<<"S"<<count<<" [ "<<(char)x.id<<" , "<<(int)x.code_length<<" ] "<<endl;
count++;
}
}
#endif