adds tree function to prob8.java