|
|
@@ -264,38 +264,10 @@ void AVLCommands::Insert(int key) {
|
|
|
// update height and balance of the tree
|
|
|
height(root_);
|
|
|
balance(lastNode);
|
|
|
-
|
|
|
- /*
|
|
|
- // Check if unbalanced
|
|
|
- // Left Left Case
|
|
|
- if (lastNode->balance_ > 1 && key < lastNode->left_->key_) {
|
|
|
- std::cout << "Left-Left" << std::endl;
|
|
|
- rightRotate(lastNode);
|
|
|
- }
|
|
|
-
|
|
|
- // Right Right Case
|
|
|
- if (lastNode->balance_ < -1 && key > lastNode->right_->key_) {
|
|
|
- std::cout << "Right-Right" << std::endl;
|
|
|
- leftRotate(lastNode);
|
|
|
- }
|
|
|
-
|
|
|
- // Left Right Case
|
|
|
- if (lastNode->balance_ > 1 && key > lastNode->left_->key_) {
|
|
|
- std::cout << "Left-Right" << std::endl;
|
|
|
- lastNode->left_ = leftRotate(lastNode->left_);
|
|
|
- rightRotate(lastNode);
|
|
|
- }
|
|
|
-
|
|
|
- // Right Left Case
|
|
|
- if (lastNode->balance_ < -1 && key < lastNode->right_->key_) {
|
|
|
- std::cout << "Right-Left" << std::endl;
|
|
|
- lastNode->right_ = rightRotate(lastNode->right_);
|
|
|
- leftRotate(lastNode);
|
|
|
- }
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
bool AVLCommands::Delete(int key) {
|
|
|
+ std::cout << "Deleting key: " << key << std::endl;
|
|
|
// base BST delete
|
|
|
std::shared_ptr<BSTNode> currentNode = root_;
|
|
|
while (currentNode != nullptr) {
|
|
|
@@ -320,12 +292,8 @@ bool AVLCommands::Delete(int key) {
|
|
|
currentNode->left_ : currentNode->right_;
|
|
|
}
|
|
|
|
|
|
- std::cout << "current node value: " << currentNode->key_ << std::endl;
|
|
|
- // update height of current node
|
|
|
- std::cout << "delete height update attempt..." << std::endl;
|
|
|
- currentNode->height_ = 1 + max(height(currentNode->left_), height(currentNode->right_));
|
|
|
- std::cout << "New height: " << currentNode->height_ << std::endl;
|
|
|
- std::cout << "delete height update attempt success" << std::endl;
|
|
|
+ height(root_);
|
|
|
+ balance(currentNode);
|
|
|
|
|
|
// Update balance factor of this ancestor's node
|
|
|
/*
|