Исправь удаление, чтобы при нем корректно выполнялась балансировка void…
- User
Исправь удаление, чтобы при нем корректно выполнялась балансировка void delet(std::string pn, int d, int m, int y, Node*& p, bool& h) { Node* q; if (p == NULL) { h = false; } else if (pn < p->key) { delet(pn, d, m, y, p->left, h); if (h) balance1(p, h); } else if (pn > p->key) { delet(pn, d, m, y, p->right, h); if (h) balance2(p, h); } else { if (p->left == NULL && p->right == NULL) { p->ht.removeItem(d, m, y); if (p->ht.isEmpty()) { delete p; p = NULL; h = true; } } else if (p->left != NULL && p->right == NULL) { p->ht.removeItem(d, m, y); if (p->ht.isEmpty()) { Node* temp = p->left; delete p; p = temp; h = true; } } else if (p->left == NULL && p->right != NULL) { p->ht.removeItem(d, m, y); if (p->ht.isEmpty()) { Node* temp = p->right; delete p; p = temp; h = true; } } else { p->ht.removeItem(d, m, y); if (p->ht.isEmpty()) { if (p->right == NULL) { Node* temp = p->left; delete p; p = temp; h = true; } else { Node* temp = p->left; Node* parent = p; while (temp->right != NULL) { parent = temp; temp = temp->right; } if (parent != p) parent->right = temp->left; else parent->left = temp->left; p->key = temp->key; p->ht = temp->ht; delete temp; h = true; } } } } if (h && p != NULL) { if (p->balance == -2) { if (p->left->balance == 1) balance2(p, h); else balance1(p, h); } else if (p->balance == 2) { if (p->right->balance == -1) balance1(p, h); else balance2(p, h); } } }
- Assistant