aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-05-30 02:00:00 +0000
committerrepl.it user2020-05-30 02:00:00 +0000
commitf7b018dc7cc885b4890413505649d7ca02b748b0 (patch)
treeafd0ca2be382ce72dcc9aa6099ab4782cb161256
parent98541727b89f66419b12c7db6619dcdb13c8216f (diff)
Latest version
-rw-r--r--src/huffman.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/huffman.cpp b/src/huffman.cpp
index b9fa954..ce90371 100644
--- a/src/huffman.cpp
+++ b/src/huffman.cpp
@@ -28,7 +28,8 @@ namespace huffman {
}
int idx = 0;
- void decode_tree(node * n, vector<bool> & v) {
+ void decode_tree(node * n, vector<bool> & v) {
+ if (idx >= v.size()) return;
if (v[idx++] == 1) {
for (int i = 0; i < 7; ++i) if (v[idx++]) n->c |= (1 << i);
}
@@ -52,7 +53,7 @@ namespace huffman {
}
void solve(node * n, vector<bool> & v, string & s) {
- if (idx > v.size()) return;
+ if (idx >= v.size()) return;
if (n->c) s += n->c, solve(root, v, s);
else v[idx++] == 0 ? solve(n->l, v, s) : solve(n->r, v, s);
}