Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the ADT Binary Tree operations as defined in this chapter, what tree of tr

ID: 3536767 • Letter: G

Question

Given the ADT Binary Tree operations as defined in this chapter, what tree of trees does the following sequence of statements produce? Implement with C++ code.

typedef int TreeItemType;

BinaryTree tree1, tree2;

tree2.setRootData(9);
tree2.attachLeft(10);
tree2.attachRight(8);
tree2.getLeftSubTree().attachLeft(2);

tree2.getLeftSubTree().getLeftSubTree().attachLeft(5);
tree2.getLeftSubTree().getLeftSubTree().attachRight(3);
tree2.getRightSubTree().attachLeft(6);
tree2.getRightSubTree().attachRight(7);

tree1.setRootData(1);
tree1.attachLeft(2);
tree1.attachRight(3);

BinaryTree bTree(4, tree2, tree1);

Explanation / Answer

#include #include #include struct tree_node { tree_node *left; tree_node *right; int data; } ; class bst { tree_node *root; public: bst() { root=NULL; } int isempty() { return(root==NULL); } void insert(int item); void inordertrav(); void inorder(tree_node *); void postordertrav(); void postorder(tree_node *); void preordertrav(); void preorder(tree_node *); }; void bst::insert(int item) { tree_node *p=new tree_node; tree_node *parent; p->data=item; p->left=NULL; p->right=NULL; parent=NULL; if(isempty()) root=p; else { tree_node *ptr; ptr=root; while(ptr!=NULL) { parent=ptr; if(item>ptr->data) ptr=ptr->right; else ptr=ptr->left; } if(itemdata) parent->left=p; else parent->right=p; } } void bst::inordertrav() { inorder(root); } void bst::inorder(tree_node *ptr) { if(ptr!=NULL) { inorder(ptr->left); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote