Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Probelm:root was not declared in this scope at 157 line Code: #include using namespace std; struct bstNode { int data; bstNode * left; bstNode *

Probelm:root was not declared in this scope at 157 lineimage text in transcribed

Code:

#include using namespace std;

struct bstNode { int data; bstNode * left; bstNode * right; }; bstNode* getNewNode(int value) { bstNode* newNode = new bstNode(); newNode->data = value; newNode->left = NULL; newNode->right = NULL; return newNode; } bstNode* Insert(bstNode *root, int value) { if(root == NULL) { root = getNewNode(value); } else if(value data) root->left = Insert(root->left,value); else root->right = Insert(root->right,value); return root; } bool Search(bstNode *root, int value) { if(root == NULL) return false; if(value == root->data) return true; else if(valuedata) return Search(root->left,value); else return Search(root->right,value); }

int FindMin1(bstNode* root) { if(root==NULL) { coutleft != NULL) { temp = temp->left; } return temp->data; }

bstNode* FindMin2(bstNode* root) { if(root->left == NULL) return root; else return FindMin2(root->left); } int FindMax1(bstNode* root) { if(root==NULL) { coutright != NULL) { temp = temp->right; } return temp->data; } int FindBigger(int a, int b) { if(a>=b) return a; else return b; } int FindHeight(bstNode* root) { if(root == NULL) return 0; else return FindBigger(FindHeight(root->left), FindHeight(root->right)) + 1; }

void PreOrder(bstNode *root) { if(root==NULL) return; coutdataleft); PreOrder(root->right); }

void InOrder(bstNode *root) { if(root==NULL) return; InOrder(root->left); coutdataright); }

void PostOrder(bstNode *root) { if(root==NULL) return; PostOrder(root->left); PostOrder(root->right); coutdata

bstNode* Delete(bstNode* root, int value) { if(root == NULL) return root; else if(root->data >value) root->left = Delete(root->left,value); else if(root->data right = Delete(root->right,value); else { if(root->left ==NULL && root->right == NULL) { delete root; root = NULL; } else if(root->left == NULL) { bstNode* temp = root; root = root->right; delete temp; } else if(root->right == NULL) { bstNode* temp = root; root = root->left; delete temp; } else { bstNode* temp = FindMin2(root->right); root->data = temp->data; root->right = Delete(root->right,temp->data); } } return root; } int main() { int a; cout>a; root = Insert(root,a); } cout

Probelm:root was not declared in this scope at 157 line

C++

share full code

Generate the Driver file (main.cpp) where you perform the following tasks: Input Values Expected Output 14 92 73 11 Operation to Be Tested and Description of Action Implement the BST structure Print if the tree is empty or not Insert ten items Print if the tree is empty or not Print the length of the tree Retrieve 9 and print whether found or not Retrieve 13 and print whether found or not Print the elements in the tree (inorder) Print the elements in the tree (preorder) Print the elements in the tree (postorder) Make the tree empty . Given a sequence of integers, determine the best ordering of the integers to insert them into a binary search tree. The best order is the one that will allow the binary search tree to have the minimum height Tree is empty 17 0 5 11 Tree is not empty 10 Item is found Item is not found 0 1 2 3 4 5 7 9 11 17 14 2013 975 11 17 1 0 3 2 5 7 17 11 9 4 11 9 42 73 17 0 5 14 10 2 395 7 11 17 Hint: Sort the sequence (use the inorder traversal). The middle element is the root. Insert it into an empty tree. Now in the same way, recursively build the left subtree and then the right subtree

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago