public void removeFoundNode(AvlNode q) {
        AvlNode r;
        // at least one child of q, q will be removed directly
        if (q.left == null || q.right == null) {
            // the root is deleted
            if (q.parent == null) {
                if (q.left != null)
                    this.root = q.left;
                else if (q.right != null)
                    this.root = q.right;
                else
                    this.root = null;
                return;
            }
            r = q;
        } else {
            // q has two children --> will be replaced by successor
            r = successor(q);
            q.element = r.element;
        }

        AvlNode p;
        if (r.left != null) {
            p = r.left;
        } else {
            p = r.right;
        }

        if (p != null) {
            p.parent = r.parent;
        }

        if (r.parent == null) {
            this.root = p;
        } else {
            if (r == r.parent.left) {
                r.parent.left = p;
            } else {
                r.parent.right = p;
            }
            // balancing must be done until the root is reached.
            recursiveheight(r.parent);
        }
        r = null;
    }