implemented pre- and post- order traversals