private void fixDoubleRed(Node child) {
        Node parent = child.parent;
        Node grandParent = parent.parent;
        if (grandParent == null) {
            parent.color = BLACK;
            return;
        }
        Node n1, n2, n3, t1, t2, t3, t4;
        if (parent == grandParent.left) {
            n3 = grandParent;
            t4 = grandParent.right;
            if (child == parent.left) {
                n1 = child;
                n2 = parent;
                t1 = child.left;
                t2 = child.right;
                t3 = parent.right;
            }
            else {
                n1 = parent;
                n2 = child;
                t1 = parent.left;
                t2 = child.left;
                t3 = child.right;
            }
        }
        else {
            n1 = grandParent;
            t1 = grandParent.left;
            if (child == parent.left) {
                n2 = child;
                n3 = parent;
                t2 = child.left;
                t3 = child.right;
                t4 = parent.right;
            }
            else {
                n2 = parent;
                n3 = child;
                t2 = parent.left;
                t3 = child.left;
                t4 = child.right;
            }
        }

        if (grandParent == root) {
            root = n2;
            n2.parent = null;
        }
        else {
            grandParent.replaceWith(n2);
        }

        n1.setLeftChild(t1);
        n1.setRightChild(t2);
        n2.setLeftChild(n1);
        n2.setRightChild(n3);
        n3.setLeftChild(t3);
        n3.setRightChild(t4);
        n2.color = grandParent.color - 1;
        n1.color = BLACK;
        n3.color = BLACK;

        if (n2 == root) {
            root.color = BLACK;
        }
        else if (n2.color == RED && n2.parent.color == RED) {
            fixDoubleRed(n2);
        }
    }