c - Deleting a node from RST tree using double pointers -


i've got rst tree structure is:

struct node {     int key;     node *left, *right; } *root; 

my function aim delete node 'v' key:

void delete (int v) {     node** p = search(v);     node** tmp = p;     if (!(*p)) return;     if((*p)->left==null && (*p)->right==null)     {         p = null;         return;     }     while((*tmp)->left != null || (*tmp)->right != null)     {         if ((*tmp)->left != null)             tmp = &((*tmp)->left);         else             tmp = &((*tmp)->right);     }     (*tmp)->right = (*p)->right;     (*tmp)->left = (*p)->left;     p = tmp;     tmp = null; } 

generally not sure when should write 'tmp' , '*tmp'. can explain me mistakes here?

(!tmp)->right == null  node** temp = p;  temp->right, temp alone pointer node pointer. has no right. (*temp)->right. 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -