Skip to content

Commit 7badc9c

Browse files
committed
add destructor to trie
1 parent 7238500 commit 7badc9c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Algorithm-DataStructure/trie.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class TrieNode {
1717
TrieNode(bool status=false) : isComplete(status) {
1818
children.resize(NUM_ALPHABET);
1919
}
20+
21+
~TrieNode() {
22+
children.clear();
23+
}
2024
};
2125

2226

@@ -26,6 +30,10 @@ class Trie {
2630
root = new TrieNode(false);
2731
}
2832

33+
~Trie() {
34+
delete root;
35+
}
36+
2937
void insert(string word);
3038
bool search(string word);
3139
bool startWith(string prefix);

0 commit comments

Comments
 (0)