Good day. The task "Create an elementary tree structure." I had difficulties with adding an element, I understand that maybe you need to recursively walk something like a tree. It is necessary to find the parent element in the tree, if it does not have such child , add the incoming child . Here root is the root of the tree.
public boolean add(E parent, E child) { if (root.eqValue(parent)) { //если наш корень это parent if (!root.contain(child)) { //и в нем нет такого child, добавляем в него child root.add(new Node<>(child)); modCount++; return true; } } else { //если parent не корень, что делать? } return false; }
parenttree itself; then in the place where you specified the comment to refer to this function. The search algorithm is recursive: see the children of the root, if you don’t have one, see the children of the children - Dmig