【发布时间】:2019-08-25 11:27:19
【问题描述】:
我需要创建一个层次结构,该结构将有多个孩子,这些孩子还可以有多个孩子。所以,我使用树来实现它,但我坚持它的实现。
我需要从数据中构建的结构是这样的:
class Node<T>
{
private T id;
private T description;
private T name;
private List<Node> children = new ArrayList<Node>();
private Node parent=null;
// then set and get methods
}
孩子可以生孩子
{
"ORGANIZATION":[
{
" id":101,
"category_name":"Organization 1",
"description":" ",
"WING ":[
//this is the category children which can also be a subcategory {
"id":122,
"category_name":"wing 1",
"description":"",
"FLOOR":[
{
"id":111,
"category_name":"floor 1"
}
]
},
{
"id":555,
"category_name":"wing 2",
"description":""
},
{
"id":222,
"category_name":"wing 3",
"description":""
}
]
},
{
"id":11111,
"category_name":"organization 2",
"description":"",
"WING":[
{
"id":4545,
"category_name":"wing 1",
"description":""
},
{
"id":252,
"category_name":"wing 2",
"description":"",
"FLOOR":[
{
"id":131,
"category_name":"floor 1",
"description":""
}
]
},
{
"id":2526,
"category_name":"Wing 3 ",
"description":"",
"FLOOR":[
{
"id":87,
"category_name":"floor 2",
"description":""
},
{
"id":565,
"category_name":"floor 3",
"description":"",
"ROOM":[
// here is an example of a child that is a sub-category also {
"id":555,
"category_name":"room 1",
"description":""
},
{
"id":584,
"category_name":"room 2",
"description":""
},
{
"id":77,
"category_name":"room 3",
"description":""
}
]
}
]
}
]
}
]
}
我被 Node 类卡住了,我不知道如何实现它。那么,是否有任何实现来形成这种结构?以及我可以在我的类节点中添加哪些其他功能。 帮帮我吧。
【问题讨论】:
标签: java data-structures tree