I\'m looking to use the following code to not check whether there is a word matching in the Trie but to return a list all words beginning with the prefix inputted by the use
This is easier to solve recursively in my opinion. It would go something like this:
Print
that prints all the nodes in the trie rooted in the node you give as parameter. Wiki tells you how to do this (look at sorting). Print
function with this node as the parameter. Then just make sure you also output the prefix before each word, since this will give you all the words without their prefix.If you don't really care about efficiency, you can just run Print
with the main root node and only print those words that start with the prefix you're interested in. This is easier to implement but slower.