Morris Traversal(前序)

Morris Traversal(前序)_第1张图片
捕获.PNG
void flatten(TreeNode* root) {
        if(!root) return ;
        TreeNode* cur = root;
        TreeNode* pre = NULL;
        while(cur){
            if(cur -> left){
                pre = cur -> left;
                while(pre -> right)
                    pre = pre -> right;
                pre -> right = cur -> right;
                cur -> right = cur -> left;
                cur -> left = NULL;
            }
            cur = cur -> right;
        }
    }

解释:


Morris Traversal(前序)_第2张图片
捕获.PNG

你可能感兴趣的:(Morris Traversal(前序))