/*
* 先序遍历二叉树(递归)
*/
public void PrintBinaryTreePreRecur(TreeNode<T> root)
{
if (root!=null)
{
System.out.print(root.data);
PrintBinaryTreePreRecur(root.left);
PrintBinaryTreePreRecur(root.right);
}
}
/*
* 中序遍历二叉树(递归)
*/
public void PrintBinaryTreeMidRecur(TreeNode<T> root)
{
if (root!=null)
{
PrintBinaryTreeMidRecur(root.left);
System.out.print(root.data);
PrintBinaryTreeMidRecur(root.right);
}
}
/*
* 后序遍历二叉树(递归)
*/
public void PrintBinaryTreeBacRecur(TreeNode<T> root)
{
if (root!=null)
{
PrintBinaryTreeBacRecur(root.left);
PrintBinaryTreeBacRecur(root.right);
System.out.print(root.data);
}
}
Java二叉树遍历
最新推荐文章于 2024-08-05 11:11:16 发布