Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE BinaryNode structure as provided to: template struct BinaryNode { Object element; BinaryNode *left; BinaryNode *right; BinaryNode(const Object & theElement, BinaryNode *lt= nullptr, BinaryNode *rt=nullptr)

USE BinaryNode structure as provided to:

template

struct BinaryNode

{

Object element;

BinaryNode *left;

BinaryNode *right;

BinaryNode(const Object & theElement, BinaryNode *lt= nullptr, BinaryNode *rt=nullptr)

: element{ theElement }, left{ lt }, right{ rt } { }

};

//A recursive function that takes an expression and makes the tree

template

void MakeTree(string expr, BinaryNode *node,int& pos)

{

}

//recursive function that prints the tree in Postfix equivalent

template

void Postfix(BinaryNode* node)

{

}

Part a:

Write recursive functions that computes the following

depth of a node

The depth of a node is the number of edges from the node to the tree's root node.

height of a node

The height of a node is the number of edges on the longest downward path between that node and a leaf.

Part b:

Write the following recursive functions,

Function that takes an expression and makes the tree

void MakeTree(string expr, BinaryNode *node,int& pos)

Function that prints the tree in Postfix equivalent

template

void Postfix(BinaryNode* node)

{

}

Function that prints the tree in Infix equivalent

template

void Infix(BinaryNode* node)

{

}

Test with the below given main which should produce the output:

BinaryNode* root = new BinaryNode(' ');

int pos = 0;

cout

MakeTree("((a+(b*c))+(((d*e)+f)*g))", root,pos);

cout

Postfix(root);

cout

Infix(root);

image text in transcribed

PLEASE answer clearly with comments. Will provide a thumbs up if above rules followed and desired output is achieved :)

CAUsers pkolliNDesktop\Fall18 CMP305\FileSystem\DebugBinary.exe Expression-((a+(bc))+( ((de)+f) g)) Postfix equivalent: a bcdef+ g * + Infix equivalent: + a(bc)) Press any key to continue de)f)g) CAUsers pkolliNDesktop\Fall18 CMP305\FileSystem\DebugBinary.exe Expression-((a+(bc))+( ((de)+f) g)) Postfix equivalent: a bcdef+ g * + Infix equivalent: + a(bc)) Press any key to continue de)f)g)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

Explore and describe what it is that you want from work.

Answered: 1 week ago

Question

Define the term intellectual property and describe its importance.

Answered: 1 week ago