镜像二叉树C++代码

本文为镜像二叉树的C++代码,为了代码简洁,将空节点和某个节点具有空孩子的情况放到了同一个逻辑下进行判断。

 

typedef struct
{
    int value;
    BTNode *pLeft;
    BTNode *pRight;
}BTNode;

void BTMirror(BTNode *pHead)
{
    if (pHead == NULL)
        return;

    BTNode *pTmp;
    pTmp = pHead->pLeft;
    pHead->pLeft = pHead->pRight;
    pHead->pRight = pTmp;

    BTMirror(pHead->pLeft);
    BTMirror(pHead->pRight);
}
posted on 2012-11-22 10:33  kkmm  阅读(373)  评论(0编辑  收藏  举报