package BinaryTree;
import java.util.Scanner;
public class BinaryTree {
public static void main(String[] args) {
}
public Treenode createbinarytree(Treenode node, Scanner scan) {//创建
String tmp = scan.next();
if (scan.next().equals("0"))
{
return node = null;
}
else
{
node = new Treenode(tmp);
{
node.setLchild(createbinarytree(node.getLchild(), scan));
node.setRchild(createbinarytree(node.getRchild(), scan));
return node;
}
}
}
public void preoder(Treenode node) {//遍历
if (node!=null)
{
System.out.println( node.getData());
preoder(node.getLchild());
preoder(node.getRchild());
}
}}
package BinaryTree;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
BinaryTree bint=new BinaryTree();
Treenode node=new Treenode();
Treenode node1;
System.out.println("请开始输入二叉树节点,输入0结束");
Scanner scan=new Scanner(System.in);
node1=bint.createbinarytree(node, scan);
bint.preoder(node1);
}
}
qq_昭阳_2
冯宝宝
相关分类