Diameter is equal to the path between the two farthest nodes leaf1 and leaf2
getDiameterPath ( leaf1 , leaf2 , -1 , path ) ; int pathSize = path . size ( ) ; if ( pathSize % 2 ) { cout << path [ pathSize / 2 ] << endl ; } else { cout << path [ pathSize / 2 ] << " , ▁ " << path [ ( pathSize - 1 ) / 2 ] << endl ; } }