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 00:40
Write a function 'music_func' that takes 3 parameters -- music type, music group, vocalist -- and prints them all out as shown in the example below. in case no input is provided by the user, the function should assume these values for the parameters: "classic rock", "the beatles", "freddie mercury". for example: input: alternative rock,pearl jam,chris cornell output: the best kind of music is alternative rock the best music group is pearl jam the best lead vocalist is chris cornell note: the print statements will go inside the for example: print("the best kind of music is"
Answers: 2
question
Computers and Technology, 22.06.2019 10:30
Think about a recent customer service experience - either positive or negative. write a brief summary of that experience. now think about those four characteristics we look for in customer service representatives. how did the representative in your example stack up? write down your answer and give specific examples.
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
Select all that apply. which of the following are proofreading options included in microsoft word? spell check find replace grammar check formatting check
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
In the context of an internet connection, llc stands for leased line connection liability limited company local loop complex local loop carrier
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
Questions on the website: 13722360