C++ codes to build random trees