package com.tree;
import java.util.Scanner;
class Tree {
static Tree tre = new Tree();
Tree left = null;
Tree right = null;
int data;
public Tree() {
}
//前序遍历创建二叉树,遇到空树写入0
public void createTree(Tree node) {
Scanner scan = new Scanner(System.in);
int tr = scan.nextInt();
node.data = tr;
if (tr != 0) {
node.left = new Tree();
node.right = new Tree();
createTree(node.left);
createTree(node.right);
}
}
// 先序遍历
public void pre(Tree tree) {
if (tree.data != 0) {
System.out.print(tree.data);
}
if (tree.left != null) {
pre(tree.left);
}
if (tree.right != null) {
pre(tree.right);
}
}
// 中序遍历
public void med(Tree tree) {
if (tree.left != null) {
pre(tree.left);
}
if (tree.data != 0) {
System.out.print(tree.data);
}
if (tree.right != null) {
pre(tree.right);
}
}
//后序遍历
public void next(Tree tree) {
if (tree.left != null) {
pre(tree.left);
}
if (tree.data != 0) {
System.out.print(tree.data);
}
if (tree.right != null) {
pre(tree.right);
}
}
}
public class erchashu {
public static void main(String[] args) {
// TODO Auto-generated method stub
Tree tree = new Tree();
tree.createTree(Tree.tre);
tree.next(Tree.tre);
}
}