subject

Project Requirements:In this project, you are asked to develop a binary expression tree and use the tree to convert postfix expressions into infix expressions. In this project, a postfix expression may contain 4 types of operators: multiplication (*), division (/), plus (+), and minus (-). We assume that multiplication and division have the same precedence, plus and minus have the same precedence, and multiplication and division have higher precedence than plus and minus. All operators are left-associative (i. e. associate left-to-right).Binary Expression Tree:. Build a binary expression tree class called "BET". Your BET class must have a nested structure named "BinaryNode" to contain the node-related information (including, e. g., element and pointers to the children nodes). In addition, BET must at least support the following interface functions:Public interfaceBET(): default zero-parameter constructor. Builds an empty tree. BET(const string& postfix): one-parameter constructor, where parameter "postfix" is string containing a postfix expression. The tree should be built based on the postfix expression. Tokens in the postfix expression are separated by spaces. BET(const BET&): copy constructor -- makes appropriate deep copy of the tree~BET(): destructor -- cleans up all dynamic space in the treebool buildFromPostfix(const string& postfix): parameter "postfix" is string containing a postfix expression. The tree should be built based on the postfix expression. Tokens in the postfix expression are separated by spaces. If the tree contains nodes before the function is called, you need to first delete the existing nodes. Return true if the new tree is built successfully. Return false if an error is encountered. const BET & operator= (const BET &): assignment operator -- makes appropriate deep copyvoid printInfixExpression(): Print out the infix expression. Should do this by making use of the private (recursive) versionvoid printPostfixExpression(): Print the postfix form of the expression. Use the private recursive function to helpsize_t size(): Return the number of nodes in the tree (using the private recursive function)size_t leaf_nodes(): Return the number of leaf nodes in the tree. (Use the private recursive function to help)bool empty(): return true if the tree is empty. Return false otherwise. Private helper functions (all the required private member functions must be implemented recursively):void printInfixExpression(BinaryNode *n): print to the standard output the corresponding infix expression. Note that you may need to add parentheses depending on the precedence of operators. You should not have unnecessary parentheses. void makeEmpty(BinaryNode* &t): delete all nodes in the subtree pointed to by t. BinaryNode * clone(BinaryNode *t): clone all nodes in the subtree pointed to by t. Can be called by functions such as the assignment operator=.void printPostfixExpression(BinaryNode *n): print to the standard output the corresponding postfix expression. size_t size(BinaryNode *t): return the number of nodes in the subtree pointed to by t. size_t leaf_nodes(BinaryNode *t): return the number of leaf nodes in the subtree pointed to by t. Make sure to declare as const member functions any for which this is appropriate

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 17:00, osirisarellane3792
*! 20 points! *jeff wants to create a website with interactive and dynamic content. which programming language will he use? a. dhtml b. html c. css d. javascript
Answers: 1
image
Computers and Technology, 24.06.2019 22:00, kingkush85
Difference between ancient and modern mode of information transmission
Answers: 1
image
Computers and Technology, 25.06.2019 04:30, greenbyron88
You can fit more raw files on a memory card than the jpeg files? truefalse
Answers: 1
image
Computers and Technology, 25.06.2019 05:10, andyboehm7411
What is the disadvantage of a mesh topology?
Answers: 1
You know the right answer?
Project Requirements:In this project, you are asked to develop a binary expression tree and use the...

Questions in other subjects:

Konu
History, 27.04.2021 03:30