Reputation: 1611
I have a data structure made of linkedlists of linkdelist.
For example:
[ [A,B,C] [D,E,F] [A,B] [E,F] ]
My goal is to find those linkedlists that are never contained in the whole structure. For istance, [A,B,C] and [D,E,F] are never contained by others, because they contain respectively [A,B] and [E,F]. I need to use recursion since I'm dealing with a tree, so when I find a linkedlist with these feature I have to recall my function.
That's my implementation:
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
}
}
}
Despite I compare all the possible combinations, I miss some nodes in the tree. Is there something wrong related to the linkedlists?
Upvotes: 0
Views: 48
Reputation: 395
Well, I guess that nested for is supposed to increment j rather than i. I suggest you to avoid naming indexes like that, it can result in a really confusing code and, at times, in this kind of errors.
Upvotes: 1