Ciao a tutti, vi presento il mio problema. Ho la seguente classe:
codice:public class GenericTreeArrayList { private GenericNode root; public class GenericNode { private int dato; private ArrayList<GenericNode> children = new ArrayList<GenericNode>(); [ ... ] public int contaNodiInterni() { if (children.size() == 0) return 0; int nodiInterni = 0; for (GenericNode child: children) nodiInterni += child.contaFoglieNodiInterni(); return nodiInterni + 1; } } public GenericTreeArrayList() { root = null; } [ ... ] Coppia contaFoglieNodiInterni() { if (root == null) return 0; else return root.contaNodiInterni(); } }
Per scorrere l'ArrayList children il Prof usa il seguente codice:
for (GenericNode child: children)
nodiInterni += child.contaFoglieNodiInterni();
Qualcuno sa spiegarmi cosa vuol dire " for (GenericNode child: children) " ? Si puo' scrivere in un altro modo?
Ad esempio:
for(int i=0; i<children.size(); i++)
nodiInterni = nodiInterni + children[i];
Grasieeeeeeeeeee![]()
![]()
![]()

Rispondi quotando
