/** * Replace the specified node with the specified replacement. This does the * replacement, then walks up the tree to ensure heights are correct, so * the replacement node should have its height set first before this method * is called. */ private void replaceChild( SimpleNode < T0> node, SimpleNode < T0> replacement) { SimpleNode < T0> nodeParent = node.parent; // replace the root if(nodeParent == null) { assert(node == root); root = replacement; // replace on the left } else if(nodeParent.left == node) { nodeParent.left = replacement; // replace on the right } else if(nodeParent.right == node) { nodeParent.right = replacement; } // update the replacement's parent if(replacement != null) { replacement.parent = nodeParent; } // the height has changed, update that up the tree fixHeightPostChange(nodeParent, true); } /**
/** * Replace the specified node with the specified replacement. This does the * replacement, then walks up the tree to ensure heights are correct, so * the replacement node should have its height set first before this method * is called. */ private void replaceChild( SimpleNode < T0> node, SimpleNode < T0> replacement) { SimpleNode < T0> nodeParent = node.parent; // replace the root if(nodeParent == null) { assert(node == root); root = replacement; // replace on the left } else if(nodeParent.left == node) { nodeParent.left = replacement; // replace on the right } else if(nodeParent.right == node) { nodeParent.right = replacement; } // update the replacement's parent if(replacement != null) { replacement.parent = nodeParent; } // the height has changed, update that up the tree fixHeightPostChange(nodeParent, true); } /**
/** * Replace the specified node with the specified replacement. This does the * replacement, then walks up the tree to ensure heights are correct, so * the replacement node should have its height set first before this method * is called. */ private void replaceChild( SimpleNode < T0> node, SimpleNode < T0> replacement) { SimpleNode < T0> nodeParent = node.parent; // replace the root if(nodeParent == null) { assert(node == root); root = replacement; // replace on the left } else if(nodeParent.left == node) { nodeParent.left = replacement; // replace on the right } else if(nodeParent.right == node) { nodeParent.right = replacement; } // update the replacement's parent if(replacement != null) { replacement.parent = nodeParent; } // the height has changed, update that up the tree fixHeightPostChange(nodeParent, true); } /**
parent.left = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted; parent.right = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted;
parent.left = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted; parent.right = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted;
parent.left = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted; parent.right = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted;
parent.left = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted; parent.right = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted;
parent.left = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted; parent.right = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted;
parent.left = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted; parent.right = inserted; fixCountsThruRoot(parent, size); fixHeightPostChange(parent, false); return inserted;