Write two function to print all words in prefix tree c++

Get your Assignment in a Minimum of 3 hours

Our academic experts are ready and waiting to assist with any writing project you may have. From simple essay plans, through to full dissertations, you can guarantee we have a service perfectly matched to your needs.

Free Inquiry Order A Paper Now Cost Estimate

I’m trying to learn for my Computer Science class and I’m stuck. Can you help?

In this lab, you will start with a solution to Lab 4, and you will add new functionality to the program. When the user types “list”, the program should print out all of the words that have been added to the PrefixTree so far, in alphabetical order. To add this functionality, you will need to implement two functions, PrefixTree::printWordList() and PrefixTreeNode::printAllWords().

PrefixTreeNode::printAllWords() is the function that will be doing most of the work. This function should recursively print all of the words that end at or below this node in the PrefixTree. The main idea is that if this node is final, you should print the word that ends here, then recursively print all of the words for all of this node’s (non-NULL) children, in alphabetical order.

To print out the word, I recommend keeping a string as a global variable: add characters to the word as you go down the tree, and remove characters as you go back up. (A better solution would be a static data member of PrefixTreeNode, but we haven’t discussed these static data members in class.) Luckily, string supports the push_back() and pop_back() operations, though you could also use concatenation and resize() or substr() to add and remove characters. Note that the root node contains the character ‘’–don’t add this character to the word.

PrefixTree::printWordList() will just need to print all of the words, starting at the root.

Like Lab 4, you will just submit a source file that includes the provided header file and implements these two functions.

"Is this question part of your assignment? We Can Help!"

"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"

Get Started