for (int i = 0; i < key.length(); i++)
{
int index = key[i] - 'a';
if (!pCrawl->children[index])
pCrawl->children[index] = getNode();
pCrawl = pCrawl->children[index];
}
pCrawl->isEndOfWord = true;
for (int i = 0; i < key.length(); i++)
{
int index = key[i] - 'a';
if (!pCrawl->children[index])
return false;
pCrawl = pCrawl->children[index];
}
return (pCrawl != NULL && pCrawl->isEndOfWord);
}
int main()
{
string keys[] = {"bad", "bat", "geeks", "geeks", "cat", "cut"};
int n = sizeof(keys)/sizeof(keys[0]);
struct TrieNode *root = getNode();
for (int i = 0; i < n; i++)
insert(root, keys[i]);
search(root, "bat")? cout << "Yes\n" :
cout << "No\n";
search(root, "gee")? cout << "Yes\n" :
cout << "No\n";
return 0;
include <bits/stdc++.h>
using namespace std;
const int ALPHABET_SIZE = 26;
struct TrieNode { struct TrieNode *children[ALPHABET_SIZE];
};
struct TrieNode getNode(void) { struct TrieNode pNode = new TrieNode;
}
void insert(struct TrieNode root, string key) { struct TrieNode pCrawl = root;
}
bool search(struct TrieNode root, string key) { struct TrieNode pCrawl = root;
}
int main() {
}