class BinartTree {
// 先序遍历
public void preOrder(TreeNode root) {
System.out.println(root);
if (root.getLeft() != null) {
preOrder(root.getLeft());
}
if (root.getRight() != null) {
preOrder(root.getRight());
}
}
// 中序遍历
public void midOrder(TreeNode root) {
if (root.getLeft() != null) {
midOrder(root.getLeft());
}
System.out.println(root);
if (root.getRight() != null) {
midOrder(root.getRight());
}
}
// 后序遍历
public void afterOrder(TreeNode root) {
if (root.getLeft() != null) {
afterOrder(root.getLeft());
}
if (root.getRight() != null) {
afterOrder(root.getRight());
}
System.out.println(root);
}
}