The pointer changes automatically in cPP, which is not controlled.

1. Question




2. Code

Node* BST :: deletemin(Node*& r){
    if(r == NULL){
        return NULL;
    }
    if(r->lc == NULL){
        if(r->rc != NULL){
            if(r->father != NULL){
                r->rc->father = r->father;
                r->father->lc = r->rc;
                return r;
            }
            else{
                cout << ":r->rc = " << r->rc << endl; 
                cout << ":root = " << root << endl;
                this->root = r->rc;
                cout << "r->rc = " << r->rc << endl;
                cout << "root = " << root << endl;
                cout << "r->rc->father" << r->rc->father << endl;
                cout << "root->father" << r->father << endl; 
                root->father = NULL;
                return r;
            }     
        } 
        else{
            Node* temp = r;
            r = NULL;
            return temp; 
        }
    }
    return deletemin(r->lc); 
}

3. Error

After the

r-> rc pointer is assigned to root, the value of the r-> rc pointer changes automatically, even though I didn"t do anything

4. Screenshot

clipboard.png

5. Attempted to resolve

I have searched all over the network, and there is no similar situation. I hope God will let me know. I would appreciate it!

6. The tail
code has been transferred, and partners who need reference can download the research
link:
extraction code: v4bz

Nov.15,2021

actually rc has changed, but r has changed.

r this input parameter is actually root . The key is how you send the parameters to deletemin . You can output & r and & root to see

before assigning values.

the following code can see the difference between the two ways.

  {
    BST bst;
    auto r = new Node;
    bst.root = r;
    bst.root->rc = new Node;
    bst.root->rc->rc = new Node;
    bst.root->rc->rc->father = bst.root->rc;
    bst.root->rc->father = bst.root;
    bst.deletemin(r);
  }
  {
    //
    BST bst;
    auto r = new Node;
    bst.root = r;
    bst.root->rc = new Node;
    bst.root->rc->rc = new Node;
    bst.root->rc->rc->father = bst.root->rc;
    bst.root->rc->father = bst.root;
    bst.deletemin(bst.root);
  }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7be49c-1f5fb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7be49c-1f5fb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?