C++ 🔥 Step-wise | Commented Code | using TRIES
Disclaimer : \nYou can understand the code BETTER, if you just have the BASIC LOGIC and the IDEA of the structure of the TRIE data structure...\nNow, just proce
# Disclaimer : \nYou can understand the code **BETTER**, if you just have the **BASIC LOGIC** and the **IDEA** of the structure of the **TRIE** data structure...\nNow, just proceed furthur to understand the code...\n\n**NOTE :** Read the corresponding comments to undertstand the code properly in detail\n# Code\n```\n//Implementing a class for defining a new data type, named trie\nclass trie{\n    public:\n    trie* a[26];\n    bool terminal;\n\n    //constructor to initialize the values\n    trie()\n    {\n        terminal=false;\n        for(int i=0;i<26;i++)\n            a[i]=NULL;\n    }\n};\n\n//given class\nclass WordDictionary {\npublic:\n\n    //creating the starting trie, named root\n    trie* root;\n\n    //contructor to initialize the values\n    WordDictionary() {\n        root=new trie;              //intializing the starting root of the trie\n    }\n    \n    //self made function to add word into our data structure\n    void add(trie* &root,string word,int index)\n    {\n        //base case starts\n        if(index==word.size())                         \n        {\n            root->terminal=true;\n            return;\n        }      \n        //base case ends\n\n        //word[index]-\'a\' will give us the proper integer index\n        if(root->a[word[index]-\'a\']==NULL)\n            root->a[word[index]-\'a\']=new trie;\n\n        add(root->a[word[index]-\'a\'],word,index+1);\n    }\n\n    //given function\n    void addWord(string word) {\n        add(root,word,0);\n    }\n    \n    //self made function to search word in our data structure\n    bool searching(trie* root,string word,int index)\n    {\n        //base cases starts\n        if(index==word.size() && root->terminal==true)\n            return true;\n        if(index==word.size() && root->terminal==false)\n            return false;\n        //base cases ends\n\n        //In the problem itself, it is given that, dot(.) might also\n        //be given while searching any string. So, whenever we get\n        //a dot, we will look at each of the pointers in our array\n        //of the current root because dot might represent any \n        //character. So, for that reason we have a FOR loop here...\n        if(word[index]==\'.\')\n        {\n            for(int i=0;i<26;i++)\n            {\n                bool a;\n                if(root->a[i]!=NULL)\n                    a=searching(root->a[i],word,index+1);\n\n                    //base case : If you get true then no need to\n                    //check further, that\'s why directly return\n                    //true from here itself. \n                    if(a==true)             \n                    return true;\n            }\n            return false;\n        }\n        //If it is not a dot, then it is definitely any other character \n        else\n        {\n            //base starts\n            if(root->a[word[index]-\'a\']==NULL)\n            return false;\n            //base case ends\n\n            return searching(root->a[word[index]-\'a\'],word,index+1);\n        }\n    }\n\n    //given function\n    bool search(string word) {\n        return searching(root,word,0);\n    }\n};\n```\nI hope that you would have understood the code and the logic behind each statement. If now also, you have any doubts regarding any statement in my code, then you can just ask me, I will clear it too...\nThankYou...\n**Don\'t forget to UPVOTE...**
['String', 'Depth-First Search', 'Design', 'Trie', 'C++']