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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -