Advertisement
Guest User

Delete_iter_abr

a guest
Apr 19th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. deleteIter(T,K){
  2.    tree*  P=NULL;
  3.    tree* curr=T;
  4.    tree* Y =NULL;
  5.    tree* X =NULL;
  6.    while(curr!=NULL && curr->key!=K) //non so precisamente dove finisca questo while penso prenda tutto perΓ²
  7.     P=curr;
  8.     if (curr->key<k)
  9.         curr=curr->Dx;
  10.     else
  11.         curr=curr->Sx;
  12.    if(curr=NIL)
  13.         return T;
  14.    else {
  15.     if (curr->Sx ==NULL || curr ->Dx == NULL)
  16.         Y=curr;
  17.     else{
  18.         Y=curr->Dx;
  19.         P=curr;
  20.             while(Y->Sx==NULL){
  21.             P=Y;
  22.             Y=Y->Sx;
  23.             }
  24.          }
  25.     }
  26.   if(Y->Sx==NIL)
  27.     X=Y->Dx;
  28.   else
  29.     X=Y->Sx;
  30.   if(P==NULL)
  31.     T=X;//dovrebbe essere l'assegnazione chiave
  32.   else {
  33.     if(Y=P->Sx)
  34.         P->Sx=X;
  35.     else
  36.         P->Dx=X;
  37.     }
  38.   if(curr != Y){
  39.     "copia Y in curr";
  40.     "dealloca(Y)";
  41.     }
  42. return T;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement