+ 1
This function is written by me for deleting a node in binary tree but not giving the expected output..
void remove(int x) { struct Node* temp=head; while(temp->data!=x) { if (temp==NULL) return; if(x<temp->data) temp=(*temp).prev; else temp=(*temp).next; } if(temp->prev!=NULL && temp->next==NULL) { struct Node* left=temp->prev; temp->data=left->data; temp->prev=left->prev; temp->next=left->next; delete (left); } else if(temp->prev==NULL && temp->next!=NULL) { struct Node* right=temp->next; temp->data=right->data; temp->prev=right->prev; temp->next=right->next; delete (right); } else if(temp->prev!=NULL && temp->next!=NULL) { struct Node* left=min(temp->prev); temp->data=left->data; delete (left); } else delete(temp); }
2 Réponses
+ 1
that is function not whole code
0
head in the first line is undefined.