this is my code snippet:

"bst *node" is the node to be deleted..Code:void deletenodebst(bst **rootptr,bst *node) { bst *ptr, *ptr1; if(node->left==NULL || node->right==NULL){ ptr = node; }else ptr = successorbst(node); if(ptr != NULL){ if(ptr->left!=NULL){ ptr1 = ptr->left; } else{ ptr1 = ptr->right; } if(ptr->parent==NULL){ *rootptr = ptr1; } else{ if(ptr == ptr->parent->left){ ptr->parent->left = ptr1; } else{ ptr->parent->right = ptr1; } } } if(ptr!=node) node->value = ptr->value; free(ptr); }

my problem is that when I try to perform this sequence:

a "dumping stack trace" error occurs on the delete 2 part.. help please? thanks..Code:insert 6 insert 20 insert 3 insert 2 insert 10 insert 100 insert 4 delete 20 delete 6 insert 16 insert 8 delete 8 delete 3 delete 16 delete 8 delete 4 delete 2 delete 10 delete 100