Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TTree* delNode(TTree *&root,int key)
- {
- if(!root)
- return ptr;
- if(root->data < key)
- root->right = del_node(root->right,key);
- if(root->data > key)
- root->left = del_node(root->left,key);
- if(root->data == key)
- {
- if(!root->right && !root->left)
- {
- ptr = NULL;
- delete root;
- return ptr;
- }
- if(!root->left && root->right)
- {
- ptr = root->right;
- delete root;
- return ptr;
- }
- if(!root->right && root->left)
- {
- ptr = root->left;
- delete root;
- return ptr;
- }
- if(root->right && root->left)
- {
- int i = 0;
- TTree *ptr1 = NULL;
- ptr = Root->right;
- ptr1 = ptr;
- while(ptr->left)
- {
- ptr1 = ptr;
- ptr = ptr->left;
- i++;
- }
- if(i!=0)
- {
- ptr1->left = ptr->right;
- ptr->right = Root->right;
- }
- ptr->left = Root->left;
- delete Root;
- Root = ptr;
- return ptr;
- }
- }
- return Root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement