problem 18 tree structure implemented
problem 18 correct