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 11:30
To hide gridline when you display or print a worksheet
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
Match the sentence fragment in the first column with the appropriate ending in the second column. a little per favore?
Answers: 1
question
Computers and Technology, 24.06.2019 12:50
Write a new lc-3 trap subroutine (i.e. a subroutine that will be invoked via the trap instruction) that will receive a numeric digit entered at the keyboard (i.e. an ascii character), echo it to the screen, and return in r0 the corresponding numeric value: so if the user types the digit '7', the character '7' will appear on the screen, but the value returned in r0 will be b0000 0000 0000 0111 (#7) you may not use any trap calls in your code - you must implement the "polling" code that interrogates the keyboard status and data registers. ; getnum_tsr ; a subroutine for obtaining a numeric value ; given ascii numeric digit input to keyboard. ; the numeric digit is echoed to the console (e.g. '7' = b0000 0000 0011 0111), ; but the value returned in r0 is the actual numeric value ; corresponding to the digit (e.g. b0000 0000 0000 0111 =
Answers: 3
question
Computers and Technology, 24.06.2019 14:00
Which computer tools allow you to communicate with coworkers, family,and friends
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
Biology, 19.12.2020 01:00
question
Engineering, 19.12.2020 01:00
question
Social Studies, 19.12.2020 01:00
question
Mathematics, 19.12.2020 01:00
Questions on the website: 13722360