算法(二)二叉树

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

        递归思想

        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);

        }

广度优先遍历多叉树:

 

猜你喜欢

转载自luckywnj.iteye.com/blog/1719618