沧海一幻觉
可以用递归模拟树要求子树拥有父树的id;绝对原创;import java.util.ArrayList;import java.util.List;public class Test2 {public static void main(String[]args){List trees = new ArrayList();int id = 1;Tree t1 = new Tree(0,id++,"我是根树");Tree t2 = new Tree(0,id++,"我是第二个根树");Tree t3 = new Tree(1,id++,"我是子树");trees.add(t1);trees.add(t2);trees.add(t3);Tree t4 = new Tree(1,id++,"树根你好");Tree t5 = new Tree(4,id++,"我不是树根");Tree t6 = new Tree(5,id++,"我才是树根");trees.add(t4);trees.add(t5);trees.add(t6);show(trees);}public static void show(List trees){for(int i=0;i trees, StringBuffer blank){blank.append(" ");System.out.println(blank + str );for(int i=0;i