-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhuffman.java
More file actions
35 lines (33 loc) · 586 Bytes
/
huffman.java
File metadata and controls
35 lines (33 loc) · 586 Bytes
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
/**
前缀编码的解码
*/
public static void expand(){
Node root = readTrie();
int N = BinaryStdIn.readInt();
for (int i = 0; i < N; i++){
Node x = root;
while (!x.isLeaf()){
if (BinaryStdIn.readBoolean()){
x = x.right();
}
else{
x = x.left;
}
}
BinaryStdOut.write(x.ch);
}
}
public static void compress(){
//...
for (int i = 0; i < input.length; i++){
String code = st[input[i]];
for (int j = 0; j < code.length(); j++){
if (code.charAt(j) == '1'){
BinaryStdOut.write(true);
}
else{
BinaryStdOut.write(false);
}
}
}
}