日期:2014-05-20  浏览次数:20705 次

这样可以实现一个多叉树么(代码如下)?
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);