I have a List of Lists structure and a recursive function called tree. In the following code it NEVER reaches the current == null statement so it will run forever.
If I cannot use null, what is the solution?
private void tree(LinkedList<LinkedList<String>> partitions, LinkedList<String> part)
{
LinkedList<String> current = findBiggerPartitionContained(partitions, part);
if (current == null) {
return;
}
tree(partitions, current);
}
private LinkedList<String> findBiggerPartitionContained(LinkedList<LinkedList<String>> partitions, LinkedList<String> part)
{
LinkedList<String> max = new LinkedList<>();
boolean flag = false;
for (LinkedList<String> item : partitions) {
if (item.size() > max.size() && part.containsAll(max)) {
max = item;
flag = true;
}
}
if (!flag)
return null;
flag = false;
return max;
}
current.isEmpty()instead ofcurrent==null