0
我有一个linkdelist链表的数据结构。链表列表与递归
例如:
[ [A,B,C] [D,E,F] [A,B] [E,F] ]
我的目标是要找到那些从来不包含在整个结构中的那些linkedlists。因为它们分别包含[A,B]和[E,F],所以[A,B,C]和[D,E,F]不会被别人包含。 我需要使用递归,因为我正在处理一棵树,所以当我找到一个具有这些特征的链表时,我必须记得我的功能。
这是我的实现:
private void treeGen(Node<LinkedList<String>> parent, LinkedList<LinkedList<String>> partitions) {
for (int i=0; i<partitions.size();i++) {
for(int j=0; i<partitions.size();i++)
{
//the condition discussed so far
if(!partitions.get(i).containsAll(partitions.get(j)) && parent.getData().containsAll(partitions.get(j)))
{
//create node
Node<LinkedList<String>> child = new Node<LinkedList<String>>();
//set value
child.setData(partitions.get(i));
//child of parent node
parent.addChild(child);
//new parent node, recursion
treeGen(child, partitions);
}
else
{
//do nothing
}
}
}
尽管我比较所有可能的组合,我错过了一些树节点。 与链表有关的错误吗?
你在这里用“包含”究竟是什么意思? – kkaosninja
欢迎来到Stack Overflow!它看起来像你需要学习使用调试器。请帮助一些[互补调试技术](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果您之后仍然有问题,请随时返回更多详情。 –