Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ #include using namespace std; // struct Node { int x; Node.left; Node. right; Node(){left = NULL; right = NULL;) Node(int d, Node 1 =

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribedC++
#include using namespace std; // struct Node { int x; Node.left; Node. right; Node(){left = NULL; right = NULL;) Node(int d, Node 1 = 0, Node* r =) { x = d; left = 1; right = r; }; //==== class Tree { private: Node ' root; public: Tree) { root = NULL; } void insert(int x) Node. ptr = new Node(x); cout * > *) { if (temp -> left == NULL) { cout X left = ptr; break; } else temp = temp -> left; } else { if (temp -> right == NULL) cout x right = ptr; break; else temp = temp -> right; cout left); cout x right); 11. public void preorder(){ inorder (root); } private void preorder (Node. temp) { if (temp != NULL) { cout x left); preorder (temp -> right); > ) public void postorder({ inorder (root); } private: void postorder (Nodetemp) { if (temp = NULL) { postorder(temp -> left); postorder (temp -> right); cout X "" } public void serial serial(root); } private void serial(Node *n) { cout left); cout right); { cout left == NULL && temp -> right == NULL) { if (temp == root) root = NULL; else if (ptemp -> left == temp) ptemp -> left = NULL; else if (ptemp right = temp) } else if (temp -> left == NULL & temp -> right != 1 if (temp =- root) root = temp -> right; else if (ptemp -> left us temp) ptemp -> left temp => right; else if (ptemp -> right us temp) ptemp -> right = temp -> left; else if (temp -> Fight == NULL & temp -> left != 1 if (temp =- root) root = temp -> left; else if (ptemp -> left temp) ptemp -> left = temp -> left; else if (ptemp -> right = temp) ptemp -> right = temp -> right; } else if (temp -> left = NULL && temp -> right = 1 Node. tempHolder = temp. ptepholder = temp; while (tempHolder -> left != NULL) ptempHolder = tempHolder; tempHolder = tempHolder -> left; ) temp -> x = tempHolder -> x; ptempHolder -> left = tempHolder -> right; } temp = tempHolder: delete temp: cout X = value) { ptemp = temp: if (temp -> X right; else if (temp -> X > value) temp = temp -> left; } if (temp == NULL) { cout left == NULL && temp -> right == NULL) if (temp = root) root = NULL; else if (ptemp => left == temp) ptemp -> left = NULL; else if (ptemp -> right == temp) ptemp -> right = NULL; else if (temp-> left == NULL && temp -> right != NULL if (tempa root) root = temp -> right; else if (ptemp => left = temp) ptemp -> left = temp -> right; else if (ptemp -> right = temp) ptemp -> right = temp -> left; } else if (temp -> right == NULL && temp -> left != NULL if (temps root) root = temp -> left; else if (ptemp -> left = temp) ptemp -> left = temp -> left; else if (ptemp -> right temp) ptemp -> right = temp -> right; else if (temp -> left != NULL && temp -> right 1= NULL Node.tempHolder = temp,ptempHolder = temp: while (tempHolder -> left != NULL) { ptempHolder = temp Holder; tempHolder = tempHolder -> left; ) temp -> X = tempHolder -> x; ptemp Holder -> left = tempHolder -> right; temp = tempHolder ) delete temp; cout left): deleteAllNodes (temp -> right); cout X

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_2

Step: 3

blur-text-image_3

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

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago