Question: A Sample Binary tree is shown below: The C++ code to create the previous tree is given below: #include using namespace std; //declaration for new

A Sample Binary tree is shown below:

A Sample Binary tree is shown below: The C++ code to create

The C++ code to create the previous tree is given below:

#include

using namespace std;

//declaration for new tree node

struct node {

int data;

struct node *left;

struct node *right;

};

//allocates new node

struct node* newNode(int data) {

// declare and allocate new node

struct node* node = new struct node();

node->data = data; // Assign data to this node

// Initialize left and right children as NULL

node->left = NULL;

node->right = NULL;

return(node);

}

int main()

{

node* root = newNode(0);

root->left = newNode(1);

root->right = newNode(2);

root->left->left = newNode(3);

root->left->right = newNode(4);

root->right->left = newNode(5);

root->right->right = newNode(6);

// The code for print should be here

delete root->right->right;

delete root->right->left;

delete root->left->right;

delete root->left->left;

delete root->right;

delete root->left;

delete root;

}

Complete the main code to print the data in the tree to the console as the following figure:

the previous tree is given below: #include using namespace std; //declaration for

0 Left Right 1 2 Left Right Left Right 3 5 0 1 1 2 3 4 5 6

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!