Flexing my algorithmic muscles in C++