首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java面试 >

这么可以实现一个多叉树么(代码如下)

2012-06-24 
这样可以实现一个多叉树么(代码如下)?public class TNodeString{public T NodeValuepublic TNodeStrin

这样可以实现一个多叉树么(代码如下)?
public class TNode<String>{
public T NodeValue;
public TNode<String> left,central,right;

public TNode(T item){
nodeValue = item;
left = central = right = null;
}
public TNode(T item,TNode<String> left,TNode<String> central,TNode<String> right){
nodeValue = item;
this.left = left;
this.central = central;
this.right = right;
}
}

public class MyTree{
TNode<String>root,//根结点(第0层)
a,b,c,//第一层结点——顶级域名
a1,a2,a3,b1,b2,b3,c1,c2,c3,//第二层结点——二级域名
a11,a12,a13,b11,b12,b13,c11,c12,c13,//第三层结点——三级域名

a112,a122,a132,
a212,a222,a231,
a312,a322,a332,

b112,b122,b132,
b212,b222,b232,
b312,b322,b332,

c112,c122,c132;
c212,c222,c232,
c312,c322,c332,//第四层结点(共9个)——www




a112 = new TNode<String>("www",null,null,null);
a122= new TNode<String>("www",null,null,null);
a132 = new TNode<String>("www",null,null,null);

a212 = new TNode<String>("www",null,null,null);
a222 = new TNode<String>("www",null,null,null);
a232 = new TNode<String>("www",null,null,null);

a312 = new TNode<String>("www",null,null,null);
a322 = new TNode<String>("www",null,null,null);
a332 = new TNode<String>("www",null,null,null);

b112 = new TNode<String>("www",null,null,null);
b122 = new TNode<String>("www",null,null,null);
b132 = new TNode<String>("www",null,null,null);

b212 = new TNode<String>("www",null,null,null);
b222 = new TNode<String>("www",null,null,null);
b232 = new TNode<String>("www",null,null,null);

b312 = new TNode<String>("www",null,null,null);
b322 = new TNode<String>("www",null,null,null);
b332 = new TNode<String>("www",null,null,null);

c112 = new TNode<String>("www",null,null,null);
c122 = new TNode<String>("www",null,null,null);
c132 = new TNode<String>("www",null,null,null);

c212 = new TNode<String>("www",null,null,null);
c222 = new TNode<String>("www",null,null,null);
c232 = new TNode<String>("www",null,null,null);

c312 = new TNode<String>("www",null,null,null);
c322 = new TNode<String>("www",null,null,null);
c332 = new TNode<String>("www",null,null,null);




a11 = new TNode<String>("baidu",null,a112,null);
a12 = new TNode<String>("sina",null,a122,null);
a13 = new TNode<String>("sohu",null,a132,null);

a21 = new TNode<String>("ifeng",null,b112,null);
a22 = new TNode<String>("qq",null,b122,null);
a23 = new TNode<String>("163",null,b132,null);

a31 = new TNode<String>("tsinghua",null,a312,null);
a32 = new TNode<String>("pku",null,a322,null);
a33 = new TNode<String>("whut",null,a332,null);

b11 = new TNode<String>("11player",null,b112,null);
b12 = new TNode<String>("goalhi",null,b122,null);
b13 = new TNode<String>("csdn",null,b132,null);

b21 = new TNode<String>("hust",null,b112,null);
b22 = new TNode<String>("whu",null,b122,null);
b23 = new TNode<String>("fudan",null,b132,null);

b31 = new TNode<String>("beijing",null,b312,null);
b32 = new TNode<String>("wuhan",null,b322,null);
b33 = new TNode<String>("shanghai",null,b332,null);



c11 = new TNode<String>("youku",null,c112,null);
c12 = new TNode<String>("tudou",null,c122,null);
c13 = new TNode<String>("ku6",null,c132,null);

c21 = new TNode<String>("ivye",null,c112,null);
c22 = new TNode<String>("zenit",null,c122,null);
c23 = new TNode<String>("rachelcarson",null,b132,null);

c31 = new TNode<String>("sjtu",null,c312,null);
c32 = new TNode<String>("sysu",null,c322,null);
c33 = new TNode<String>("ustc",null,c332,null);




a1 = new TNode<String>("com",a11,a12,a13);
a2 = new TNode<String>("com",a21,a22,a23);
a3 = new Tnode<String>("edu",a31,a32,a33);

b1 = new TNode<String>("com",b11,b12,b13);
b2 = new TNode<String>("edu",b21,b22,b23);
b3 = new Tnode<String>("gov",b31,b32,b33);

c1 = new TNode<String>("com",c11,c12,c13);
c2 = new TNode<String>("org",c21,c22,c23);
c3 = new Tnode<String>("edu",c31,c32,c33);




root = new TNode<String>(null,a,b,c);
a = new TNode<String>("cn",a1,a2,a3);
b = new TNode<String>("cn",b1,b2,b3);
c = new TNode<String>("cn",c1,c2,c3);


}

[解决办法]
好难噢、

热点排行