Skip to content

Commit 975cefb

Browse files
comments added
1 parent cbef527 commit 975cefb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Datastructures/TrieTree.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#include<string.h>
33
#include<stdbool.h>
44
using namespace std;
5-
5+
// structure definition
66
typedef struct trie
77
{
88
struct trie *arr[26];
99
bool isEndofWord;
1010
} trie;
11-
11+
// create a new node for trie
1212
trie *createNode()
1313
{
1414
trie *nn = new trie();
@@ -18,6 +18,7 @@ trie *createNode()
1818
return nn;
1919
}
2020

21+
// insert string into the trie
2122
void insert(trie *root, char* str)
2223
{
2324
for (int i = 0; i < strlen(str); i++)
@@ -36,6 +37,7 @@ void insert(trie *root, char* str)
3637
root->isEndofWord = true;
3738
}
3839

40+
// search a string exists inside the trie
3941
bool search(trie *root, char* str, int index)
4042
{
4143
if (index == strlen(str))
@@ -49,7 +51,9 @@ bool search(trie *root, char* str, int index)
4951
return false;
5052
return search(root->arr[j], str, index + 1);
5153
}
52-
54+
/* removes the string if it is not a prefix of any other
55+
string, if it is then just sets the endofword to false, else
56+
removes the given string*/
5357
bool deleteString (trie *root, char* str, int index)
5458
{
5559
if (index == strlen(str))

0 commit comments

Comments
 (0)