added a modified Morris algorithm for pre-order traversal