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...

Re: leaves and nodes mathematical expression 80 80

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.