|
|
@@ -327,7 +327,18 @@ bool AVLCommands::Delete(int key) {
|
|
|
|
|
|
|
|
|
int AVLCommands::DeleteMin() {
|
|
|
- return DeleteMin(root_);
|
|
|
+ int deletedKey = DeleteMin(root_);
|
|
|
+ height(root_);
|
|
|
+
|
|
|
+ std::shared_ptr<BSTNode> smallestNode = root_;
|
|
|
+ std::shared_ptr<BSTNode> lastNode = nullptr;
|
|
|
+ while (smallestNode != nullptr) {
|
|
|
+ lastNode = smallestNode;
|
|
|
+ smallestNode = smallestNode->left_;
|
|
|
+ }
|
|
|
+ balance(lastNode);
|
|
|
+
|
|
|
+ return deletedKey;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -417,9 +428,10 @@ std::string AVLCommands::JSON() const {
|
|
|
auto v = nodes.front();
|
|
|
nodes.pop();
|
|
|
std::string key = std::to_string(v->key_);
|
|
|
- //std::string height = std::to_string(v->height_);
|
|
|
- //result[key]["height"] = height;
|
|
|
- result[key]["left"] = v->left_->key_;
|
|
|
+ std::string balance = std::to_string(v->balance_);
|
|
|
+ result[key]["balance factor"] = balance;
|
|
|
+ std::string height = std::to_string(v->height_);
|
|
|
+ result[key]["height"] = height;
|
|
|
if (v->left_ != nullptr) {
|
|
|
result[key]["left"] = v->left_->key_;
|
|
|
nodes.push(v->left_);
|
|
|
@@ -436,5 +448,6 @@ std::string AVLCommands::JSON() const {
|
|
|
}
|
|
|
}
|
|
|
result["size"] = size_;
|
|
|
+ std::cout << result << std::endl;
|
|
|
return result.dump(2) + "\n";
|
|
|
}
|