add same tree (java and cpp version)