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, 22.06.2019 20:50
What is the difference between windows 7 and windows 10?
Answers: 1
question
Computers and Technology, 23.06.2019 01:30
Jason works as an accountant in a department store. he needs to keep a daily record of all the invoices issued by the store. which file naming convention would him the most? a)give the file a unique name b)name the file in yymmdd format c)use descriptive name while naming the files d)use capital letters while naming the file
Answers: 3
question
Computers and Technology, 23.06.2019 15:00
What is the total resistance in a circuit that contains three 60 ohm resistors connected in a series? a. 20 ohms b. 120 ohms c. 60 ohms d. 180 ohms
Answers: 2
question
Computers and Technology, 23.06.2019 21:30
Which of the following includes the three primary network access technologies? dsl, cable modem, broadband lan, wan, man voip, uc, iptv tcp/ip, ftp, dhcp
Answers: 2
You know the right answer?
Write a C++ program to print the elements of binary trees using preorder, inorder, and postorder tra...
Questions
question
Computers and Technology, 10.09.2019 00:10
Questions on the website: 13722363