Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TREE::usuwanie(NODE*&el){
- // cout << "usuwanie elementu " << el->val << endl;
- if(el->right == NULL && el->left == NULL){
- if(el->parent == NULL){
- root = NULL;
- }
- else if(el->parent->left == el){
- el->parent -> left = NULL;
- }
- else{
- el->parent ->right = NULL;
- }
- delete el;
- return;
- }
- if(el->right!=NULL^el->left!=NULL){
- NODE*tmp;
- if(el->right!=NULL){
- tmp = el->right;
- }
- else{
- tmp=el->left;
- }
- tmp->parent = el->parent;
- // cout << "element tmp: " << tmp->val << endl;
- if(el->parent == NULL){
- root = tmp;
- }
- else if(el->parent->left == el){
- el->parent -> left = tmp;
- }
- else{
- el->parent ->right = tmp;
- }
- delete el;
- // cout << "element tmp po usunieciu: " << endl;
- // tmp->wypisz();
- return;
- }
- NODE*tmp = el->right;
- while(tmp->left != NULL){
- tmp = tmp->left;
- }
- el->val=tmp->val;
- usuwanie(tmp);
- }
Advertisement
Add Comment
Please, Sign In to add comment