forked from rehan-azaz/Text-Compression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImpNode.cs
65 lines (58 loc) · 1.6 KB
/
ImpNode.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Huffman_Coding
{
class ImpNode:IComparable<ImpNode>
{
public string symbol;
public int frequency;
public string code;
public ImpNode parent;
public ImpNode right;
public ImpNode left;
public bool leaf;
public ImpNode(string input)
{
symbol = input;
frequency = 1;
parent = null;
right = null;
left = null;
leaf = true;
code = "";
}
public ImpNode(ImpNode n1, ImpNode n2)
{
leaf = false;
parent = null;
code = "";
if (n1.frequency >= n2.frequency)
{
right = n1;
left = n2;
right.parent = left.parent = this;
symbol = n1.symbol + n2.symbol;
frequency = n1.frequency + n2.frequency;
}
else if (n1.frequency < n2.frequency)
{
right = n2;
left = n1;
left.parent = right.parent = this;
symbol = n1.symbol + n2.symbol;
frequency = n1.frequency + n2.frequency;
}
}
public int CompareTo(ImpNode node)
{
return this.frequency.CompareTo(node.frequency);
}
public void increaseinFrequency()
{
frequency++;
}
}
}