Algorithms in C++: Assignment 5 Solution