递归交换左右树
二叉树的镜像
http://www.nowcoder.com/questionTerminal/564f4c26aa584921bc75623e48ca3011
使用递归的思路:每访问一个结点,就交换其左右树。
struct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; void Mirror(TreeNode* pRoot) { if (pRoot == NULL) return ; struct TreeNode* t; t = pRoot->left; pRoot->left = pRoot->right; pRoot->right = t; Mirror(pRoot->left); Mirror(pRoot->right); }