package ru.job4j.simpleTree;
import java.util.*;

public class Tree<E extends Comparable<E>> implements SimpleTree<E> {

    Node<E> root;

    public Tree(E value) {
        this.root = new Node<>(value);
    }

    @Override
    public boolean add(E parent, E child) {
        if (findBy(parent).isPresent()) {
            Node<E> element = findBy(parent).get();
            element.add(new Node<>(child));
            return true;
        } else {
           return false;
        }
    }

    @Override
    public Optional<Node<E>> findBy(E value) {
        Optional<Node<E>> rsl = Optional.empty();
        Queue<Node<E>> data = new LinkedList<>();
        data.offer(this.root);
        while (!data.isEmpty()) {
            Node<E> el = data.poll();
            if (el.eqValue(value)) {
                rsl = Optional.of(el);
                break;
            }
            for (Node<E> child : el.leaves()) {
                data.offer(child);
            }
        }
        return rsl;
    }

    public class treeIterator<E> implements Iterator {

        List next = root.leaves();

        @Override
        public boolean hasNext() {
            return next != null;
        }

        @Override
        public Object next() {
            return next.iterator().next();
        }
    }

    @Override
    public Iterator<E> iterator() {
        return new treeIterator();
    }
}
@@ -1049,24 +1049,71 @@
 Iterator %7B%0A%0A
+        Queue%3CNode%3E data = new LinkedList%3C%3E();%0A
         List
@@ -1290,30 +1290,42 @@
             
-return
+Node node = (Node)
  next.iterat
@@ -1333,24 +1333,86 @@
 r().next();%0A
+            data.offer(node);%0A            return data.poll();%0A
         %7D%0A  

task #1711