Share
Explore BrainMass

C++ Binary Tree to handle single word data

My goal is to develop some binary tree routines in C++ that will handle single word data. The binary tree will be maintained as an ordered tree.

The routines I need are:

Add - add a new word to tree (do not allow duplicates).
Search - look up a word in the tree and indicate if the word is in the structure or not.
Traverse (in-order, pre-order, post-order) - label tree output with traversal order used to print the tree.

Attached is the input file. The commands should be executed in the order given. Where it says an order type such as inorder, that means to print the tree so far, in that way.

I have code for a lot of this but it needs checking. I do not have much experience with string functions, so try to use them as less as possible.

Attachments

Solution Preview

Please find attached 508716.cpp that fixes your existing code and adds processing of treeinput.txt commands to it. Please compare it with your existing code, so that you know where you went wrong and how close you were to right code.

Output generated by the fixed program is pasted below for your cross-checking. Please let me know if you do not understand anything in the fixed code or find any error/issue.

Processing commands from 'treeinput.txt'

Adding kindness ...
Adding rascal ...
Adding structures ...
Adding man ...
Adding forest ...
Adding mice ...
Adding manoman ...
Adding until ...
Adding rascals ...
Adding yahoo ...
Adding jack ...
Adding jammers ...
Adding kindman ... ...

Solution Summary

Solution is hardly using any string functions apart from string usages like "infile >> stringvar", "cout << stringvar", "stringvar comparisonoperator somevalue".

$2.19