二叉树

设计在链式存储结构上交换二叉树中所有结点左右子树的算法

//注意到左右子树交换结点交换是一个递归的过程,具体操作如下:

//判断二叉树是否为空,若为空,则无需交换,否则递归交换左右孩子的指针

typedef struct node{
    int data;
    struct node *lchild,*rchild;
}bitree;

void swapbitree(bitree *bt)
{
    bitree *p;
    if(bt == NULL)
        return;
    swapbitree(bt->lchild);//交换根结点左子树上的结点的左右孩子结点
    swapbitree(bt->rchild);
    p = bt->lchild;//最后交换根结点的左右孩子结点
    bt->lchild = bt->rchild;
    bt->rchild = p;
}
原文地址:https://www.cnblogs.com/emptyCoder/p/5468723.html