0

please help me find the error in this code. whenever i try to get the successor, the program gets the status access violation error. i think it's the parameter. i try using the minimum function outside the delete and it works. but when i try it inside the delete i get the error. why?

here's the code for the successor:

```
node* successor(node **root){
if((*root)->right == NULL && (*root)->left == NULL)return NULL;
else{
if((*root) -> right != NULL){
printf("root %d", temp -> value);
printf("pasok sa ryt\n");
return minimum(&(*root) -> right);
}
else return maximum(&((*root)-> left));
}
}
```

and here's the delete:

```
void delete(node **root, int val){
node* temp;
node* suc;
printf("entered delete?");
temp = search2(&(*root),val);
printf("\n\n");
view(temp,0);
//case 3. two children
if(temp -> left != NULL && temp -> right != NULL){
printf("pasok sa case 3");
suc = successor(&temp);
//printf("successor: %d", suc -> value);
temp -> value = suc -> value;
printf("which means lumabas sa successor?");
if(suc -> parent-> right == suc) suc ->parent -> right = NULL;
else suc -> parent -> left = NULL;
free (successor);
}//end of case 3.
else{
//case 1. no child
if(temp -> left ==NULL && temp -> right == NULL){
printf("dito papasok dapat!\n");
//if left child ung node.
if(temp -> parent -> right == NULL){
temp -> parent -> left = NULL;
free (temp);
//if right child.
}else if(temp -> parent -> left == NULL){
temp -> parent -> right = NULL;
free (temp);
}
}//end of case 1
//case 2. one child
else if(temp -> left != NULL || temp -> right != NULL){
if(temp -> left == NULL){ //no left child, so update right child and pointers. right child ang meron siya.
if(temp -> parent -> left == temp){//left child ung root [ ung dapat idelete]
temp -> parent -> left = temp -> right;
free (temp);
}else{//right child ung root na dapat idelete;
temp -> parent -> right = temp -> right;
free (temp);
}
}else if(temp -> right == NULL){//no right child.left child ang meron siya
if(temp -> parent -> left == temp){//left child ung root [ ung dapat idelete]
temp -> parent -> left = temp -> left;
free (temp);
}else{//right child ung root na dapat idelete;
temp -> parent -> right = temp -> left;
free (temp);
}
}
}//end of case 2.
}//else
}
```