Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Generic Binary Search Tree Project c + + In this project you will be creating a binary search tree to store words read from the
Generic Binary Search Tree Project c
In this project you will be creating a binary search tree to store words read from the file specified on the command line, and displaying the contents of the tree in pre in and post order traversals.
Requirements:
If the command line doesnt have argument, an error message should be displayed.
Open the file specified in the command line argument, verify the file opened successfully, if the file fails to open, an error message should be displayed.
Read in the entire file the code can assume there will only be one word on each line
As each word is read, add it to a binary search tree
After reaching the end of the file, do a preorder traversal of the tree, printing out the word stored in each node
Then do an inorder traversal of the tree, again displaying the words as each node is visited. The words should be displayed in alphabetical order.
Ask the user to search for a word or q to quit. Tell the user if the corresponding word is in the binary tree.
After the user selects q to quit, delete all the tree nodes by using a postorder recursive traversal, printing the string stored in the node before it is deleted.
Implementation suggestions:
Use ifstream::open to open the file specified on the command line
Use ifstream::isopen to verify the file opened correctly
Use getlineifstream str function to read a line of text
Use ifstream::eof to determine when the end of file is reached sample word list hapless
immerse
stretch
oatmeal
occur
eyes
direct
weather
abrasive
boundless
sloppy
uproot
thankful
injure
forgive
bun
adorable
bit
faucet
absent
acidic
party
contrast
woebegone
vacation
vary
puny
hardtofind
heavenly
body
hearing
aberrant
produce
insert
next
peace
frantic
aggressive
summon
needless
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started