Skip to content

Commit

Permalink
lab 5 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-anastasiia committed Dec 5, 2024
1 parent e704b59 commit a3f2529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions LibraryCPPClass/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ int AssociativeArray::countNodes(Node* node) const {

AssociativeArray::AssociativeArray() : root(nullptr) {}

AssociativeArray::~AssociativeArray() {
clear(root);
}


void AssociativeArray::clear(Node* node) {
if (node) {
clear(node->left);
clear(node->right);
delete node;
}
}

void AssociativeArray::insert(const std::string& key, const std::string& value) {
root = insert(root, key, value);
}
Expand Down
2 changes: 2 additions & 0 deletions LibraryCPPClass/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class AssociativeArray {
Node* find(Node* node, const std::string& key) const;
Node* remove(Node* node, const std::string& key);
int countNodes(Node* node) const;
void clear(Node* node);

public:
AssociativeArray();
~AssociativeArray();
void insert(const std::string& key, const std::string& value);
std::string find(const std::string& key) const;
void remove(const std::string& key);
Expand Down

0 comments on commit a3f2529

Please sign in to comment.