Solution2_a Code:Find Inorder Predecessor publicTreeNodepredecessor(TreeNode root,TreeNode p){if(root==null)returnnull;if(root.val>=p.val){returnpredecessor(root.left,p);}else{TreeNode right=predecessor(root.right,p);return(right!=null)?right:root;}} Solution2_b Code:Find Inorder Success...
// root.val <= p.val. In this case, root cannot be p's inorder successor, neither can root's left child. So we only need to consider root's right child, thus we move root to its right and check again. // We continuously move root until exhausted. To this point, we only need...
A binary tree isthreadedby making all right child pointers that would normally be null point to the inorder successor of the node (ifit exists), and all left child pointers that would normally be null point to the inorder predecessor of the node. 就是说线索二叉树实际上是把所有原本为空的...
/* A method to traverse a tree using Morris traversal, hence without using recursion or stack */ void MorrisTraversal(struct treeNode* root) { struct treeNode *current, *predecessorofCurrent; if (root == NULL) return; current = root; //The while loop continues till our current root is ...
"A binary tree isthreadedby making all right child pointers that would normally be null point to the inorder successor of the node, and all left child pointers that would normally be null point to the inorder predecessor of the node." ...