• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing an Arithmetical Expression – Creating an Expression Tree  RSS feed

 
Charles Cole
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a Java program to create a binary expression tree in which:  leaves are (double) numbers, and interior
nodes are binary algebraic operators). As an example, the expression  1 2 + 3 *  could be represented as:



The input to the program is an arithmetical expression (already) in postfix notation. Use for testing the sample :   
4 8 2 / * 10  7 ‐ + ( equivalent to 4*8/2+(10‐7) ) .  
After creating the corresponding expression tree, print it’s traversal in Pre‐Order, In‐Order, and Post‐Order.
Evaluate the expression and print its final value (for this example, result should be: 19.00).

I'm not really certain how I would go about solving this problem, can anyone help me get started and guide me in the right direction?
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about a stack for the operators and for the operands. How would you proceed?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!