I have a node structure, each node have children nodes but no parent node. I need to iterate over this structure while collecting info to 3 doubles. Since java have no references I can’t use recursion unless I will create a class for these doubles, and also I can’t do it without recursion since the nodes are parent-less.
Is there a way to do it in java without changing the structure or creating another class?
The structure:
public class Skeleton
{
public Vector2D head;
public int numberOfNodes;
public Skeleton[] nodes;
public int skeletonSize;
public Color color;
...
}
If you declare:
results will be a pointer to a three element array of doubles. You can pass it around during your recursion, and modify the elements as needed.
However, don’t be afraid to create extra classes in Java. You can declare a class inside one of your other classes, for local use.