I want to implement a tree like data structure in java for activity objects, where nodes can be shared between two parents. I want to build a hierarchy of activities, where one activity can be contained by multiple activities. How can I do it? Or should I use some other data structure and how?
问问题
587 次
2 回答
1
像这样的东西应该工作:
public class Activity {
private Activity parent1;
private Activity parent2;
private List<Activity> children;
// other fields, getters, setters, methods, etc
}
于 2012-07-12T19:09:42.107 回答
0
要决定设计,了解如何导航结构至关重要。如果只是自上而下,您所需要的只是让 Activity 包含其子项的列表。如何确保最多两个活动拥有某个活动是另一回事。如果您需要确保这一点,那么您可能需要在活动中使用父参考。
于 2012-07-12T19:14:29.467 回答