-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuffmanNode.java
More file actions
41 lines (35 loc) · 1.22 KB
/
HuffmanNode.java
File metadata and controls
41 lines (35 loc) · 1.22 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
// Mary Huibregtse
// CSE 143
// HW 8
// TA Shanti Camper Singh
// Class HuffmanNode constructs and manages nodes
import java.util.*;
public class HuffmanNode implements Comparable<HuffmanNode> {
public int character; //integer value of character
public int frequency; // frequency of character
public HuffmanNode left; // reference to left subtree
public HuffmanNode right; // reference to right subtree
// Post: constructs leaf node with given character and
// frequency
public HuffmanNode(int character, int frequency) {
this(character, frequency, null, null);
}
//Post: constructs node with zero frequency and zero
// character values
public HuffmanNode() {
this(0,0,null,null);
}
// Post: constructs branch node with given character and
// frequency and links
public HuffmanNode(int character, int frequency,
HuffmanNode left, HuffmanNode right) {
this.character = character;
this.frequency = frequency;
this.left = left;
this.right = right;
}
// returns comparable
public int compareTo(HuffmanNode other) {
return (this.frequency - other.frequency);
}
}