DEV Community

Leo
Leo

Posted on

el



void btree::el(int x){

cout << "el " << x << endl;
node p* = r;
node *q = nullptr;
cout << " el1"";

while(p && p -> data() !=x){

    q = p;
    if(x < p ->data()){
        p = p -> left();
    }else{
        p = p -> right();
    }
}

cout << "asd";
if(!p) return;
cout << "nanana"

//hoja
if(p == nullptr){

    if(p == r) r = nullptr;
    else if (q -> left()) q -> left(nullptr);
    else q -> right();


//izquierdo

}else if(!p ->left()){

    if(p == r) r = p -> right();
    else if (q -> left()) q -> left(p -> right());
    else q -> right(p -> right());

//derecho

}else if(!p ->right()){

    if(p == r) r = p -> left();
    else if (q -> left()) q -> left(p -> left());
    else q -> right(p -> right());

//dos   
}else{
    if(p == r) r = p -> right();
    else if (q -> left()) q -> left(p -> left());
    else q -> right(p -> right());


    node *aux = p -> right();
    while(aux -> left()) aux = aux -> left();
    aux -> left(p -> left());
}

delete p;
_tamaño --;
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)