private void updateNumNodes() { int n = 1; for (Tree<T> child : children) { n += child.numNodes; } this.numNodes = n; if (this.parent != null) this.parent.updateNumNodes(); }
private void updateNumNodes() { int n = 1; for (Tree<T> child : children) { n += child.numNodes; } this.numNodes = n; if (this.parent != null) this.parent.updateNumNodes(); }
public void addSubtreeAt(Tree<T> tree, T edgeLabel, int position) { tree.parent = this; children.add(position, tree); childrenEdgeLabels.add(position, edgeLabel); // update statistics numNodes += tree.numNodes; if (this.parent != null) this.parent.updateNumNodes(); // update flags yieldChanged = true; heightChanged = true; }
public void addSubtreeAt(Tree<T> tree, T edgeLabel, int position) { tree.parent = this; children.add(position, tree); childrenEdgeLabels.add(position, edgeLabel); // update statistics numNodes += tree.numNodes; if (this.parent != null) this.parent.updateNumNodes(); // update flags yieldChanged = true; heightChanged = true; }
public void addSubtree(Tree<T> tree, T edgeLabel) { // this could be written as a specific instance of addSubtreeAt, but the // insertion at a specific position is O(n), while what is done here is // O(1) tree.parent = this; children.add(tree); childrenEdgeLabels.add(edgeLabel); // update statistics numNodes += tree.numNodes; if (this.parent != null) this.parent.updateNumNodes(); // update flags yieldChanged = true; heightChanged = true; }
public void addSubtree(Tree<T> tree, T edgeLabel) { // this could be written as a specific instance of addSubtreeAt, but the // insertion at a specific position is O(n), while what is done here is // O(1) tree.parent = this; children.add(tree); childrenEdgeLabels.add(edgeLabel); // update statistics numNodes += tree.numNodes; if (this.parent != null) this.parent.updateNumNodes(); // update flags yieldChanged = true; heightChanged = true; }