Basically, each comment has a list of its child comments. Then, when you're going to print out a tree, you recursively also print out child comments.