算法(二)二叉树

来源:互联网 发布:u盘什么牌子好 知乎 编辑:程序博客网 时间:2024/06/07 03:34

 

深度优先遍历二叉树:先根后根中根

        递归思想

        void XXBL(tree* root){                //先序遍历

                //Do Something with root

                if(root->lchild!=NULL) XXBL(root->lchild);

                if(root->rchild!=NULL) XXBL(root->rchild);

        }

 

        void ZXBL(tree* root){                //中序遍历

                if(root->lchild!=NULL) ZXBL(root->lchild);

                //Do Something with root

                if(root->rchild!=NULL) ZXBL(root->rchild);

 

        }

 

广度优先遍历多叉树:

 
原创粉丝点击