binary-search-tree/red-black-tree

View on GitHub
src/deletion/prune.js

Summary

Maintainability
A
0 mins
Test Coverage
import assert from 'assert';

import Node from '../types/Node.js';

/**
 * Prune subtree rooted at input node.
 *
 * @param {Node} root - The root of the subtree to prune.
 */
const prune = (root) => {
    assert(root instanceof Node);
    assert(root.parent !== null);

    if (root === root.parent.left) root.parent.left = null;
    else root.parent.right = null;
};

export default prune;