Added function to do pre-order traversal of the tree