程序员面试题精选100题(11)-求二元查找树的镜像[数据结构](2)

时间:2019-09-22 编辑:多美文
BSTreeNode *pNode = stackTreeNode.top();
            stackTreeNode.pop();

            // swap the right and left child sub-tree
            BSTreeNode *pTemp = pNode->m_pLeft;
            pNode->m_pLeft = pNode->m_pRight;
            pNode->m_pRight = pTemp;

            // push left child sub-tree into stack if not null
            if(pNode->m_pLeft)
                  stackTreeNode.push(pNode->m_pLeft);

            // push right child sub-tree into stack if not null
            if(pNode->m_pRight)
                  stackTreeNode.push(pNode->m_pRight);
      }
}

本文已影响
相关文章