C++ Version of an Age-Old Algorithm