Computers and Technology

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 ->

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:30, Daud2020
What kind of motivation is katrina showing? use the drop-down menu to complete the statement. katrina is using motivation because she is personally interested in learning more.
Answers: 2
image
Computers and Technology, 23.06.2019 01:20, sosick90501
Write a function balancechemical to balance chemical reactions by solving a linear set of equations. the inputs arguments are: reagents: symbols of reagents in string row array products: symbols of products in string row array elements: elements in the reaction in string row array elcmpreag: elemental composition of reactants in two dimensional numeric array elcmpprdcts: elemental composition of prducts in two dimensional numeric array hint: the first part of the problem is setting up the set of linear equations that should be solve. the second part of the problem is to find the integers from the solution. one way to do this is to mulitiply the rational basis for the nullspace by increasing larger integers until both the left-and right-side integers exist. for example, for the reaction that involves reacting with to produce and : reagents=["ch4", "o2"]; products =["co2", "h2o"]; elements =["c","h", "o"] elcmpreag=[1,4,0;
Answers: 3
image
Computers and Technology, 23.06.2019 09:10, babyskitt
Effective character encoding requires standardized code. compatible browsers. common languages. identical operating systems.
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, ryleerose255
Idon’t understand the double8 coding problem. it is java
Answers: 1
Do you know the correct answer?
Write a C++ program to print the elements of binary trees using preorder, inorder, and postorder tra...

Questions in other subjects:

Konu
History, 25.07.2019 08:00