diff options
author | Anthony Wang | 2020-05-30 02:00:00 +0000 |
---|---|---|
committer | repl.it user | 2020-05-30 02:00:00 +0000 |
commit | f7b018dc7cc885b4890413505649d7ca02b748b0 (patch) | |
tree | afd0ca2be382ce72dcc9aa6099ab4782cb161256 | |
parent | 98541727b89f66419b12c7db6619dcdb13c8216f (diff) |
Latest version
-rw-r--r-- | src/huffman.cpp | 5 |
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);
}
|