The strings will be taken as input from the user and added as root node, then as subsequent left and right nodes of the tree. The user has the choice to display all the nodes or only the left nodes or right nodes of the tree.
- Inserting the nodes into the tree was difficult as they are not integers whose position in the tree can be determined using the usual algorithm: if(root->info >val) insert(root->left,val); else insert(root->right,val);
Once the program is run, it shows the four options:
The tree must have a root node, a left node and right node to the root. After that it is up to the user, to add any number of nodes.
To insert the root node, simply enter 1, then the value of the node. Then insert the root->left and root->right, to do that, enter 1, then press y, and enter the respective values.
To create a tree like above, the following is to be done:
Note that the first question is always answered with 'y' as every node will be below root node
This option will print all the nodes of the tree. It will be of the form: (root->data) -> (root->left->data) --- (root->data) -> (root->right->data)
For a tree like the one above, the output will be:
It will print all the left-most nodes of the tree.
It will print all the right-most nodes of the tree.
I learnt how to combine the concept of binary tree with string functions and arrays, which thereby helped in successful implementation of a binary tree using strings.