有两列数据,表示了一棵或者两棵树。两列相同的为根。后面的列表示其父节点。
A A
C A
B C
D C
E E
F E
G F
把这个树换种方式表示
换成如下,只有一个根的树,第一列递增id,第二列是父节点的id
0 -1 root
1  0 A
2  1 C
3  2 B
4  2 D
5  0 E
6  5 F
7  5 G以上2数据结构均自己设计,树是可以多个分支的,非二叉树。

解决方案 »

  1.   

    就像你的第二种就可以了
    id parentid name
    1  0        root
    2  1        a
    3  1        b
    4  2        c
    ……
     
      

  2.   

    楼主到最后也没有说出是什么问题。
    public class Tree {
     public Tree(int parent,int id,String str) {
      this.parent = parent;
      this.id = id;
      this.str = str;
     }
     int parent;
     int id;
     String str;
    }
    使用递归就好了