This function is written by me for deleting a node in binary tree but not giving the expected output.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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); }

5th Jun 2018, 7:45 PM
Akshay Karande
2 Answers
+ 1
that is function not whole code
6th Jun 2018, 3:19 AM
Akshay Karande
0
head in the first line is undefined.
5th Jun 2018, 7:49 PM
Bebida Roja
Bebida Roja - avatar