|
@@ -13,8 +13,14 @@ TEMPLATE(HOLDER) NODE::Node() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-TEMPLATE(HOLDER) NODE::Node(Type& value) {
|
|
|
- _value = typename Container::Node(value);
|
|
|
+TEMPLATE(HOLDER) NODE::~Node() {
|
|
|
+ for (int i = 0; i < TIRE_NODE_NUMBER; ++i) {
|
|
|
+ if (_next[i] != nullptr) {
|
|
|
+ delete _next[i];
|
|
|
+ _next[i] = nullptr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _value = nullptr;
|
|
|
}
|
|
|
// #pragma endregion
|
|
|
|
|
@@ -23,11 +29,19 @@ TEMPLATE(HOLDER) ADT::Tire() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+TEMPLATE(HOLDER) ADT::~Tire() {
|
|
|
+ for (int i = 0; i < TIRE_NODE_NUMBER; ++i) {
|
|
|
+ delete _root._next[i];
|
|
|
+ _root._next[i] = nullptr;
|
|
|
+ }
|
|
|
+ _root._value = nullptr;
|
|
|
+}
|
|
|
+
|
|
|
TEMPLATE(typename ITERATOR) ADT::find(const std::string& key) {
|
|
|
Node* curr = &_root;
|
|
|
Node* next = nullptr;
|
|
|
for (const char& ch : key) {
|
|
|
- next = curr->_next[(const int)ch];
|
|
|
+ next = curr->_next[INDEX(ch)];
|
|
|
if (next == nullptr) {
|
|
|
return end();
|
|
|
}
|
|
@@ -44,7 +58,7 @@ TEMPLATE(typename ITERATOR) ADT::insert(const std::string& key, Type& value) {
|
|
|
Node* curr = &_root;
|
|
|
Node* next = nullptr;
|
|
|
for (const char& ch : key) {
|
|
|
- next = curr->_next[(const int)ch];
|
|
|
+ next = curr->_next[INDEX(ch)];
|
|
|
if (next != nullptr) {
|
|
|
curr = next;
|
|
|
continue;
|