Code for various algorithms, C++