C++ version of  Robert Sedgewick's algorithms4