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++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -