DIgital dictionary 628

i am getting runtime error for search function can anybody help

Hello @neeleshr628,

The problem is with the following code:

void searchnew(trienode* root,string word)
{ int count=0;
 int index;
    for(int i=0;i<26;i++)
    {
        if(i==26)
            return;
        if(root->child[i]!=NULL)
        {   index=i;
            word=word+char(i+'a');
        }
        else if(root->isterminal==true)
            cout<<word<<endl;
        searchnew(root->child[index],word);
    }
} 

When would it actually terminate?

It is because of the wrong placement of the recursion call:
searchnew(root->child[index],word);

Solution:
Dry run the above-mentioned code to understand your fault.

Hope, this would help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.