-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNode.java
More file actions
80 lines (65 loc) · 1.8 KB
/
Node.java
File metadata and controls
80 lines (65 loc) · 1.8 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
package Huffman;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Node implements Comparable<Node>, Serializable {
Paire p;
Node left;
Node right;
public Node(Paire cle, Node left, Node right) {
this.p = cle;
this.left = left;
this.right = right;
}
public Node(Paire cle) {
this.p = cle;
}
public Node() {
this.p = null;
}
public void insert(Node x) {
if (p == null) {
left = x.left;
} else {
left = this;
}
right = x.right;
p = x.p;
}
@Override
public int compareTo(Node n) {
return p.compareTo(n.p);
}
public boolean isLeaf() {
return right == null && left == null;
}
public static Node build(Paire cle, Node left, Node right) {
return new Node(cle, left, right);
}
public static void serialaze(Node x, String src) throws IOException {
try {
try (FileOutputStream ostream = new FileOutputStream(src)) {
ObjectOutputStream p = new ObjectOutputStream(ostream);
p.writeObject(x);
p.flush();
ostream.close();
}
} catch (Exception ex) {
}
}
public static Node deserialaze(String src) throws IOException {
try {
FileInputStream istream = new FileInputStream(src);
ObjectInputStream q = new ObjectInputStream(istream);
Node new_tree = (Node) q.readObject();
istream.close();
q.close();
return new_tree;
} catch (Exception ex) {
}
return null;
}
}