Implemented preorder tree traversal.