二叉树遍历-JAVA实现

二叉树遍历分为前序、中序、后序递归和非递归遍历、还有层序遍历。

1 //二叉树节点 2 public class BinaryTreeNode { 3 private int data; 4 private BinaryTreeNode left; 5 private BinaryTreeNode right; 6 7 public BinaryTreeNode() {} 8 9 public BinaryTreeNode(int data, BinaryTreeNode left, BinaryTreeNode right) { 10 super(); 11 this.data = data; 12 this.left = left; 13 this.right = right; 14 } 15 16 public int getData() { 17 return data; 18 } 19 20 public void setData(int data) { 21 this.data = data; 22 } 23 24 public BinaryTreeNode getLeft() { 25 return left; 26 } 27 28 public void setLeft(BinaryTreeNode left) { 29 this.left = left; 30 } 31 32 public BinaryTreeNode getRight() { 33 return right; 34 } 35 36 public void setRight(BinaryTreeNode right) { 37 this.right = right; 38 } 39 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgjwjj.html