Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the code for all the tree traversal functions. Run the program, your code should display the following output. #### INORDER TRAVERSAL ##### 4 2

Complete the code for all the tree traversal functions. Run the program, your code should display the following output.
#### INORDER TRAVERSAL #####
427581369
#### PREORDER TRAVERSAL #####
124578369
#### POSTORDER TRAVERSAL #####
478529631
#include
using namespace std;
struct node{
int element;
node *left;
node *right;
node(int element){
this->element = element;
left= right=nullptr;
}
};
void process(int element){
cout << element <<"";
}
void inorderTraversal(node * n){
//insert code here for inorderTraversal
}
void preorderTraversal(node * n){
//insert code here for preorderTraversal
}
void postorderTraversal(node * n){
//insert code here for postorderTraversal
}
int main(int argc, const char * argv[]){
node *root = new node(1);
node *node2= new node(2);
node *node3= new node(3);
node *node4= new node(4);
node *node5= new node(5);
node *node6= new node(6);
node *node7= new node(7);
node *node8= new node(8);
node *node9= new node(9);
root->left = node2;
root->right = node3;
node2->left = node4;
node2->right = node5;
node5->left = node7;
node5->right = node8;
node3->right = node6;
node6->right = node9;
cout <<"#### INORDER TRAVERSAL #####"<< endl;
inorderTraversal(root);
cout << endl <<"#### PREORDER TRAVERSAL #####"<< endl;
preorderTraversal(root);
cout << endl<<"#### POSTORDER TRAVERSAL #####"<< endl;
postorderTraversal(root);
return 0;
}

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

=+5. What do you want them to think?

Answered: 1 week ago

Question

=+What the product does for the end-user.)

Answered: 1 week ago