问题描述
importjava.lang.Object;importjava.lang.String;importjava.lang.Math;classBiNode//二叉树结点类{privateObjectdata;privateBiNodelchild,rchild;BiNode(Objectdata){this.data=data;}BiNode(Objectdata,BiNodelchild,BiNoderchild){this.data=data;this.lchild=lchild;this.rchild=rchild;}publicObjectgetData(){returndata;}publicvoidsetData(Objectdata){this.data=data;}publicBiNodegetlchild(){returnlchild;}publicBiNodegetrchild(){returnrchild;}publicvoidsetlchild(BiNodelchild){this.lchild=lchild;}publicvoidsetrchild(BiNoderchild){this.rchild=rchild;}publicStringtoString(){returndata.toString();}}classBiTree//二叉树类{privateBiNoderoot;privateinti=0;//用以计算publicBiTree()//无参构造函数{root=newBiNode(null,null,null);}publicvoidCreat(BiNoderoot,Stringstr,intj)//以扩展二叉树方式创建二叉树{charch=str.charAt(j);j++;if(ch=='#'){//root=newBiNode(null,null,null);root.setData(null);return;}else{root.setData(ch);Creat(root.getlchild(),str,j);Creat(root.getrchild(),str,j);}}publicvoidPreOrder(BiNoderoot)//前序遍历{if(root.getData()==null)return;else{System.out.println(root.getData());PreOrder(root.getlchild());PreOrder(root.getrchild());}}}publicclassHi{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubStringstr="AB#D##C##";//从控制台或文本框得到的字符串//String[]result=str.split("\s");//字符串处理BiNoderoot=newBiNode(null);BiTreebitree=newBiTree();intj=1;bitree.Creat(root,str,j);bitree.PreOrder(root);}}很简单的一段代码,但是跑的时候报错见附件调用对象未正常初始化,这里都是高手,唉,本吊正在从国企狗转行码农,帮忙看下吧,谢谢了。