This week, I am finishing up my "coursework" in Stanford's CS106B course. It covers programming abstractions in C++.

I have two more assignments, plus I'll probably tackle some of the section homeworks for additional review.

I am currently working on an Huffman encoding program. Even though I've done this already for my Scala course, writing it again through the imperative paradigm has proven challenging.

The decoding process leaves me stuck. This was how I originally wrote the code.

This approach worked fine for text-only files, but crashed upon decoding a compressed image file. I found this alternative formulation through a repo. (Which was infuriatingly more elegant than my approach.)

This version works fine with image fines. Comparing the two, I'm at a loss for why theirs works and mine does not.

Any thoughts?