/** * Il metodo restituisce una collezione iterabile di tutti i nodi a profondità ( conto da root che * vale 0 fino alla fino=i) * * @param T l'albero sul quale operare * @param i la profondità * @return la collezione iterabile */ public static <E> Iterable<Position<E>> atDepth(Tree<E> T, int i) throws InvalidPositionException { PositionList<Position<E>> lista = new NodePositionList<Position<E>>(); // lista vuota LinkedTree<E> albero = (LinkedTree<E>) T; // cast Iterable<Position<E>> temp; // lista iterabile if (i == 0) { lista.addLast(T.root()); } else { temp = atDepth(T, i - 1); for (Position<E> v : temp) { PositionList<Position<E>> child = albero.checkPosition(v).getChildren(); for (Position<E> ww : child) lista.addLast(ww); } } return lista; }