-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.cpp
More file actions
98 lines (90 loc) · 1.92 KB
/
Copy pathDriver.cpp
File metadata and controls
98 lines (90 loc) · 1.92 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
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
#include<iostream>
#include<string>
#include<fstream>
#include "Task1.cpp"
#include "Task2.cpp"
using namespace std;
int main()
{
TreeLinklist T1;
string value1;
string input1;
Tree T;
string value;
string input;
int length=0;
cout<<"\nPress 1: for Task1 \n";
cout<<"\nPress 2: for Task2 \n";
cout<<"\nEnter Choice \n";
int choice;
cin>>choice;
switch (choice)
{
case 1:
{
cout<<"\nFile Name : \n";
cin>>input1;
value1=LinklistFileRead(input1);
cout<<endl;
T1.insertList(value1);
cout<<"\n Character Frequency\n";
T1.printList(T1.Root);
string* A1L;
A1L=new string[128];
char* A2L;
A2L = new char[120];
string* AAL;
int IL = 0;
AAL = T1.HUFList(A1L,IL,A2L,T1.Root);
cout<<"\nCharatcer Huffman Code\n";
for (int i = 0; i < IL; i++)
{
cout << A2L[i] << " " << A1L[i] << endl;
}
}
break;
case 2:
{
cout<<"\nFile Name : \n";
cin>>input;
value=FileRead(input);
cout<<endl;
T.insert(value);
cout<<"\n Character Frequency\n";
T.print(T.Root);
string* A1;
A1=new string[128];
char* A2;
A2 = new char[120];
string* AA;
int I = 0;
AA = T.HUF(A1,I,A2,T.Root);
cout<<"\nCharatcer Huffman Code\n";
for (int i = 0; i < I; i++)
{
cout << A2[i] << " " << A1[i] << endl;
}
int A3[128];
for (int i = 0; i < 128; i++)
A3[i] = 0;
for (int i = 0; i < value.length(); i++)
{
A3[int(value[i])]++;
}
int total=0;
for(int i=0;i<I;i++)
{
int q1,q2,q3;
q1=int(A2[i]);
q2=A3[q1];
q3=q2*A1[i].length();
total=total+q3;
}
float ARB=float(total)/float(value.length());
ARB=float(8)/ARB;
cout<<"Compression Ratio is Given as :"<<ARB<<endl;
}
default:
break;
}
}