  if(z->left == NULL || z->right == NULL) y = z;
  else y = Successor(z);
  if(y->left != NULL) x = y->left;
  else x = y->right;
  if(x != NULL) x->parent = y->parent;
  if(y->parent == NULL) T = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  if(y != z) z->key = y->key;
}
node* Successor(node* x){
  node *y;
  if(x->right != NULL) return Minimum(x->right);
  y = x->parent;
  while(y != NULL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
node* Minimum(node* x){
  while(x->left != NULL) x = x->left;
  return x;
}
node* Maximum(node* x){
  while(x->right != NULL) x = x->right;
  return x;
}