ok guys... so here's a nice one...

suppose i have a matematical expression with variables less than 10 and greater than 0... and i divide the mathematical expression in leaves and nodes, being the operands the leaves and the operators the nodes...
something like this:

(w+x)*(y-z)

          [B]*[/B]
         / \
        [B]+[/B]  [B] -[/B]
       / \  | \  
      [B]w   x y  z[/B]

hope you understand it... :P

the problem is: the mathematical expression must be input by the user, and the program must break it down... and at the end it must show the result...

the problem is: the mathematical expression must be input by the user, and the program must break it down...

Any user input has to be validated first. Once you read the string you need to go over it and make sure that all of the parentheses are matched the right way and all of the operators have the right number of operands.

When the string is validated, you can convert it to reverse polish notation and build the expression tree from that.

This article has been dead for over six months. Start a new discussion instead.