如何将树转换为其镜像树。例如。
1 1
/ \ / \
2 3 to 3 2
/ \
4 4
最佳答案
执行后序遍历。
void mirror(struct node* node)
{
if (node!=NULL)
{
struct node* temp;
/* do the subtrees */
mirror(node->left);
mirror(node->right);
/* swap the pointers in this node */
temp = node->left;
node->left = node->right;
node->right = temp;
}
}
关于将二叉树转换为其镜像树的 C 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31056729/