二叉树的镜像

void MirrorRecursively(BinaryTreeNode* pRoot)
{
	if (pRoot == nullptr || (pRoot->m_pLeft == nullptr && pRoot->m_pRight == nullptr))
		return;

	BinaryTreeNode* pTemp = pRoot->m_pLeft;
	pRoot->m_pLeft = pRoot->m_pRight;
	pRoot->m_pRight = pTemp;

	if (pRoot->m_pLeft)
		MirrorRecursively(pRoot->m_pLeft);
	if (pRoot->m_pRight)
		MirrorRecursively(pRoot->m_pRight);
}

  

posted on 2021-02-16 21:03  Noora&w  阅读(45)  评论(0编辑  收藏  举报