/** * Add child to parent Node if value does not exist in direct path from child to root * node, i.e. in any ancestralnode. * @param parent parent node * @param child the child node to add. * @return null if the value in child is not in confilct with value in any ancestor Node, otherwise return the conflicting ancestor Node. */ public Node<T> add(Node<T> parent, Node<T> child){ Node<T> node = parent; while (node != null ) { if (node != root && node.getValue().equals(child.getValue())) { return node; } node = node.getParent(); } child.setParent(parent); parent.getChildren().add(child); return null; }
/** * Add child to parent Node if value does not exist in direct path from child to root * node, i.e. in any ancestralnode. * @param parent parent node * @param child the child node to add. * @return null if the value in child is not in confilct with value in any ancestor Node, otherwise return the conflicting ancestor Node. */ public Node<T> add(Node<T> parent, Node<T> child){ Node<T> node = parent; while (node != null ) { if (node != root && node.getValue().equals(child.getValue())) { return node; } node = node.getParent(); } child.setParent(parent); parent.getChildren().add(child); return null; }
/** * Add child to parent Node if value does not exist in direct path from child to root * node, i.e. in any ancestralnode. * @param parent parent node * @param child the child node to add. * @return null if the value in child is not in confilct with value in any ancestor Node, otherwise return the conflicting ancestor Node. */ public Node<T> add(Node<T> parent, Node<T> child){ Node<T> node = parent; while (node != null ) { if (node != root && node.getValue().equals(child.getValue())) { return node; } node = node.getParent(); } child.setParent(parent); parent.getChildren().add(child); return null; }
/** * Add child to parent Node if value does not exist in direct path from child to root * node, i.e. in any ancestralnode. * @param parent parent node * @param child the child node to add. * @return null if the value in child is not in confilct with value in any ancestor Node, otherwise return the conflicting ancestor Node. */ public Node<T> add(Node<T> parent, Node<T> child){ Node<T> node = parent; while (node != null ) { if (node != root && node.getValue().equals(child.getValue())) { return node; } node = node.getParent(); } child.setParent(parent); parent.getChildren().add(child); return null; }