http://www.cnblogs.com/grandyang/p/4293853.html
用递归,先把左子树、右子树处理好,然后再将当前根节点和左、右子树进行处理。
处理的方式是将左子树换到右子树,且左子树为空,之前的右子树在整个新生成的右子树的最右节点
class Solution { public: void flatten(TreeNode* root) { if(root == NULL) return; flatten(root->left); flatten(root->right); TreeNode* tmp = root->right; root->right = root->left; root->left = NULL; while(root->right) root = root->right; root->right = tmp; } };