Customer Service Chat
Get quote & make Payment
Expression Tree, Programming Languages
For this assignment you will read a file expression.txt and create an expression tree. The expression will be a valid infix expression with the all the necessary parentheses so that there is no ambiguity in the order of the expression. You will evaluate the expression and print the result. You will also write the prefix and postfix versions of the same expression without any parentheses.
In an expression tree the nodes are either operators or operands. The operators will be in the set [''+'', ''-'', ''*'', ''/'']. The operands will be either integers or floating point numbers. All the operand nodes will be leaves of the expression tree. All the operator nodes will have exactly two children.
The outline of your program will be as follows:
class Stack (object):
class Node (object):
class Tree (object):
def __init__ (self):
def createTree (self, expr):
def evaluate (self, aNode):
def preOrder (self, aNode):
def postOrder (self, aNode):
The function createTree() will take as input parameter an infix expression with parentheses as a String and create an Expression Tree from it. Assume that the expression string is valid.
You will take the expression string and break it into tokens. There are four different kinds of tokens - left parenthesis, right parenthesis, operator, and operand. When we read a left parenthesis we are starting a new expression and when we read a right parenthesis we are ending an expression. Here is the algorithm that you will use:
If the current token is a left parenthesis add a new node as the left child of the current node. Push current node on the stack and make current node equal to the left child.
If the current token is an operator set the current node''s data value to the operator. Push current node on the stack. Add a new node as the right child of the current node and make the current node equal to the right child.
If the current token is an operand, set the current node''s data value to the operand and make the current node equal to the parent by popping the stack.
If the current token is a right parenthesis make the current node equal to the parent node by popping the stack if it is not empty.
For the input file this is what your program will output:
( ( 8 + 3 ) * ( 7 - 2 ) ) = 55
Prefix Expression: * + 8 3 - 7 2
Postfix Expression: 8 3 + 7 2 - *
Posted Date: 4/20/2012 9:52:36 AM | Location : United States
Ask an Expert
Expression Tree, Assignment Help, Ask Question on Expression Tree, Get Answer, Expert's Help, Expression Tree Discussions
Write discussion on Expression Tree
Your posts are moderated
Write your message here..
Java input stream, Expertsmind brings you unique solution in java assignme...
Expertsmind brings you unique solution in java assignments I.O streams The Java.io packages contains nearly every category you might ever need to execute feedback and resu
Undetermined coefficients, We now require starting looking into finding a p...
We now require starting looking into finding a particular solution for n th order differential equations. The two ways which we'll be looking at are similar as those which we look
Overview of procedure-oriented programming paradigm, Procedure-oriented pro...
Procedure-oriented programming (POP):- This is a top-down programming approach, where the problem is viewed as a sequence of tasks to be done such as calculating, printing etc. A n
A traveler wants to purchase a number of traveler''s checks, A traveler wan...
A traveler wants to purchase a number of traveler''s checks, each having a set amount for four different currencies: Mexican pesos, Euro dollars, Swiss francs, and US dollars. A t
What do you meant by a function, (a) (i) What do you meant by a function? ...
(a) (i) What do you meant by a function? Are functions required when writing a C program? (ii) State one of the advantages to the use of functions. (iii) What do you meant by a
program that uses a hash structure, Write a Perl program that uses a hash ...
Write a Perl program that uses a hash structure. The program should use a larger number of operations (100 or more) on this hash. To do that, use a random number generator to creat
Network management configuratio, You will create a simple network managemen...
You will create a simple network management configuration which checks that certain programs are running on your network and are performing as expected, and that certain system det
Write a function that will read the atoms for a protein, Write a function r...
Write a function readPDBfile('filename') that will read the atoms for a protein stored in a PDB file, whose name is provided as an input to the function (note that this name should
Find the cookies expiring, Your program can be invoked with option: -d date...
Your program can be invoked with option: -d date, where date is entered in dd/mm/yyyy format. In this case, it must only print the following string: Found cookies expiring bef
Assembly language, I need help with having a user input a year, and my prog...
I need help with having a user input a year, and my program to spit out what day of the week Christmas is on.... any helping hands on this?
Accounting Assignment Help
Economics Assignment Help
Finance Assignment Help
Statistics Assignment Help
Physics Assignment Help
Chemistry Assignment Help
Math Assignment Help
Biology Assignment Help
English Assignment Help
Management Assignment Help
Engineering Assignment Help
Programming Assignment Help
Computer Science Assignment Help
IT Courses and Help
Why Us ?
~24x7 hrs Support
~Quality of Work
~Time on Delivery
~Privacy of Work
Human Resource Management
Literature Review Writing Help
Follow Us |
T & C
Copyright by ExpertsMind IT Educational Pvt. Ltd.