zoukankan      html  css  js  c++  java
  • 二叉树

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

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

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

    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;
    }
  • 相关阅读:
    css优化总结
    几种常用的图片格式
    css布局总结
    第四章复习题
    4.9,4.10
    4.8
    4.7指针
    libffi
    代理模式
    Redis 汇总
  • 原文地址:https://www.cnblogs.com/emptyCoder/p/5468723.html
Copyright © 2011-2022 走看看