C++ Implementation for some algorithms.