显然你必须使用类似树的数据结构。这是它的示例代码。高级代码思想class Entity{ // declare you attributes and below two properties List<Entity> children; boolean isleafNode;// for parent node its 'false' and for leaf node it will 'true' }