Trie in C++
Implementation of Trie data structure in C++. GitHub: sourcecode/trie.h #include <iostream> #include <unordered_map> #include <string> using namespace std; /* trie class */ class trie { public: //trienode class class trienode { public: char m_ch; //char which node holds it bool m_endofstring; //end of string //trie class should have 26 pointers (characters in alphabets) to point the child nodes, //as it takes more memory also not all the child nodes are used, instead of creating the 26 pointer nodes //used unordered_map to hold child nodes. //unorderemap is based on hash table, it doesn't store sorted values. unordered_map<char, trienode*> child; int count; //num of shared prefix for different words //constructor trienode() : m_ch{ '\0' }, m_endofstring(false), count(0) { } trienode(char ch) :m_ch(ch), m_endofstring(false),count(0) { } //add character as child of the current node...