Algorithms in C++: Assignment 3 Solution