myTree。h
# include “myTree.h” void initBiTree (myTree * pTreeRoot) { ,,,//如果根节点不为空说明树在使用中,需要先销毁 ,,,if (NULL !=, pTreeRoot) ,,,{ ,,,,,,,destoryBiTree (pTreeRoot); ,,,} ,,,pTreeRoot =,空; }//思考如何使用循环销毁一棵树 void destoryBiTree (myTree * pTreeRoot) { ,,,if (NULL !=, pTreeRoot) ,,,{ ,,,,,,,if (NULL !=, pTreeRoot→pLeft) ,,,,,,,{ ,,,,,,,,,,,//递归,从最后一层向上销毁左孩子 ,,,,,,,,,,,destoryBiTree (pTreeRoot→pLeft); ,,,,,,,} ,,,,,,,//能用else if 吗? ? ? ,,,,,,,if (NULL !=, pTreeRoot→pRight) ,,,,,,,{ ,,,,,,,,,,,destoryBiTree (pTreeRoot→pRight); ,,,,,,,} ,,,,,,,自由(pTreeRoot); ,,,,,,,pTreeRoot =,空; ,,,} } void , preOrderTraverse (myTree * pTreeRoot) { ,,,if (NULL ==, pTreeRoot) ,,,{ ,,,,,,,返回; ,,,} ,,,//访问根节点 ,,,printf (" % d \ t”,, pTreeRoot→数据); ,,,preOrderTraverse (pTreeRoot→pLeft); ,,,preOrderTraverse (pTreeRoot→pRight); ,,,返回; } void inOrderTraverse (myTree * pTreeRoot) { ,,,if (NULL ==, pTreeRoot) ,,,{ ,,,,,,,返回; ,,,} ,,,inOrderTraverse (pTreeRoot→pLeft); ,,,//访问根节点 ,,,printf (" % d \ t”,, pTreeRoot→数据); ,,,inOrderTraverse (pTreeRoot→pRight); ,,,返回; } void nexOrderTraverse (myTree * pTreeRoot) { ,,,if (NULL ==, pTreeRoot) ,,,{ ,,,,,,,返回; ,,,} ,,,nexOrderTraverse (pTreeRoot→pLeft); ,,,nexOrderTraverse (pTreeRoot→pRight); ,,,//访问根节点 ,,,printf (" % d \ t”,, pTreeRoot→数据); ,,,返回; } int getTreeDepth (myTree *, pTreeRoot) { ,,,int leftDepth; ,,,int rightDepth; ,,,if (NULL ==, pTreeRoot) ,,,{ ,,,,,,,return 0; ,,,} ,,,if (NULL !=, pTreeRoot→pLeft) ,,,{ ,,,,,,,leftDepth =, getTreeDepth (pTreeRoot→pLeft); ,,,} ,,, ,,,{ ,,,,,,,leftDepth =, 0; ,,,} ,,,if (NULL !=, pTreeRoot→pRight) ,,,{ null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null二叉树- - - - - -待完善