即在转换后的二元查找树中,左子树的结点都大于右子树的结点。
用递归和循环两种方法完成树的镜像转换。
例如输入:
8
/ /
6 10
/ / / /
5 7 9 11
输出:
8
/ /
10 6
/ / / /
11 9 7 5
定义二元查找树的结点为:
struct BSTreeNode // a node in the binary search tree (BST)
{
int m_nValue; // value of node
BSTreeNode *m_pLeft; // left child of node
BSTreeNode *m_pRight; // right child of node
用递归和循环两种方法完成树的镜像转换。
例如输入:
8
/ /
6 10
/ / / /
5 7 9 11
输出:
8
/ /
10 6
/ / / /
11 9 7 5
定义二元查找树的结点为:
struct BSTreeNode // a node in the binary search tree (BST)
{
int m_nValue; // value of node
BSTreeNode *m_pLeft; // left child of node
BSTreeNode *m_pRight; // right child of node
};
#include <stdio.h>
typedef struct BSTreeNode // a node in the binary search tree (BST)
{
int nValue; // value of node
struct BSTreeNode *pLeft; // left child of node
struct BSTreeNode *pRight; // right child of node
}BSTreeNode_T;
void Revertsetree(BSTreeNode_T *pRoot)
{
if(NULL == pRoot)
return;
BSTreeNode_T *p = NULL;
p = pRoot->pLeft;
pRoot->pLeft = pRoot->pRight;
pRoot->pRight = p;
if(NULL != pRoot->pLeft)
Revertsetree(pRoot->pLeft);
if(NULL != pRoot->pRight)
Revertsetree(pRoot->pRight);
p = NULL;
}
int main(void)
{
return 0;
}