tree visits c++ implementation