Question: Questions: 1) What kind of tree does the code below generate? 2) Modify it to do all 3 traversals (Pre-order traversal, In-order traversal, and Post-order

Questions:

1) What kind of tree does the code below generate?

2) Modify it to do all 3 traversals (Pre-order traversal, In-order traversal, and Post-order traversal).

3) Use rand() to generate data. Now what do you get? - I am unsure what was ment by this question so if anyone knows that would be great, if not I guess it is ok to just reply cannot answer 3.

4) How do you organize the input to produce the tree in the image? Prove this with your code

_____________________________________________________________________________________________________________________________________________________

Code:

#include #include struct myTree{ int val; struct myTree *right, *left; }; typedef struct myTree _node; void insert(_node *(*tree), _node *item){ if(!(*tree)){ *tree = item; return; } if (item->val val) insert(&(*tree)->left , item); else if (item->val > (*tree)->val) insert(&(*tree)->right , item); } void traverse (_node *tree){ if(tree->left != NULL) traverse(tree->left); printf("%d ",tree->val); if (tree->right != NULL) traverse(tree->right); } void main (){ _node *current, *root; int i; root = NULL; for(i = 0; i left = current ->right = NULL ; current->val = i; insert( &root, current); } traverse(root); }

_____________________________________________________________________________________________________________________________________________________

Image of tree: I am unsure if 7 6 and 8 are part of the tree or not

Questions: 1) What kind of tree does the code below generate? 2)

5

/ \

3 7

/ \ / \

2 4 6 8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!