subject

Write a C++ program to print the elements of binary trees using preorder, inorder, and postorder traversal. The program includes the following: Declare and implement functions preorder, inorder, and postorder in the file funcs. cpp
// funcs. cpp
#include< iostream>
using namespace std;
template
struct BinaryNode
T element;
BinaryNode left;
BinaryNode right;
BinaryNode(const T & d T()) : element(d)
left nullptr;
right nullptr;
//print the elements of binary tree in preorder
template
void preorder (const BinaryNode* root)
// add your code
//print the elements of binary tree in inorden
template
void inorder(const BinaryNode root)
// add your code
//print the elements of binary tree in postorder
void postorder(const BinaryNode root)
// add your code ename T>
The main function is contained in the file lab06. cpp
// lab06.cpp
#include "funcs. cpp..
BinaryNode BinaryNode* node_A = new BinaryNode('A');
BinaryNode* node B = new BinaryNode('B');
BinaryNode* node C = new BinaryNode('C');
BinaryNode* node D = new BinaryNodeI'D');
BinaryNode* node E = new BinaryNode('E');
node_A->left = node_B;
node A->right = nodē_C;
node B->left = node D;
node B->right = nodē E;
return node_A; }
int main()
BinaryNode* root = create_binary_tree();
// add your code
// call three traversal functions to print elements
Please read the comments and implement the three traversal functions in treeTraversal. cpp
Then complete the following steps:
1. In the main(), declare a binary tree root in which elements are char type, and call three traversal functions to print the elements of this binary tree.
2. Compile and run the program to make sure that your functions work correctly.
3. Add a new function create_binary_tree_int(), in which elements are integers.
4. In the main(), declare a binary tree root_int which is created by the function create_binary_tree_int(), and call three traversal functions to print the elements of this binary tree.
5. Compile and run the program to make sure that your functions work correctly.
The expected result:
preorder: A -> B -> D -> E -> C ->
inorder: D -> B -> E -> A -> C->
postorder: D - E -> B - C -> A ->
preorder: 1 -> 7 -> 2 -> 6 -> 5 -> 11 -> 3 -> 9 -> 4 ->
inorder: 2 -> 7 -> 5 -> 6 -> 11 -> 1 -> 3 -> 4 -> 9 ->
postorder: 2 -> 5 -> 11 -> 6 -> 7 -> 4 -> 9 -> 3 -> 1 ->

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:20
Your program will make use of long long int variables for all calculations. note: the use of long long int requires that you have c++11 support. you should have this automatically if you are using a newer version of visual studio. the support is there for gcc as well, but you may need the -std=c++11 or -std=c++0x compiler flag. you first need to read in the total number of seconds. there is no prompt for the read (that is, you just do the cin without using a cout to display a prompt). this is going to seem a little strange when you are running your program in your ide
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
Who can provide you with a new password when you have forgotten your old one? your provide you with a new password in case you forget your old one.
Answers: 3
question
Computers and Technology, 23.06.2019 07:00
To produce a starlight effect in her photograph, lina should choose the filter for her camera.
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
Using the list, you can select the number of photos that will appear on each slide. a. theme b. frame shape c. pictures in album d. picture layout
Answers: 1
You know the right answer?
Write a C++ program to print the elements of binary trees using preorder, inorder, and postorder tra...
Questions
question
Mathematics, 24.03.2021 16:30
Questions on the website: 13722362