Friday, July 31, 2009

C++............?

hi...


i need to create a class called 'expression' and include appropriate member functions to covert a valid infix expression to postfix form...can any one explain ...hw to do this??..


pls hep me write a program for this.....

C++............?
you get help from http://tutorialofc.blogspot.com/
Reply:There are a number of ways to do this. I think it might boil down to whether you want to create a parse tree of the infix expression, say with each node holding either a value or an operator and the left and right nodes for an operator node being the values or subexpressions combined by that operator; or you create a postfix stack as you parse the expression.





How I solve the problem might depend on what else I need to do with the class. For example, if the class exists only to do this conversion, then it's a waste of a class because this can be done with a handful of recursive functions. So I'm betting the class might also be used to calculate the value of the expression or as part of a larger parser, like the front end of a compiler.





With that in mind I might parse the infix expression into the tree I described above. Such a tree can be easily walked to find a value for the expression or walked in another way to create the postfix stack.





I'm sure the differences between infix and postfix were discussed in class, and by now you've had sufficient exposure to data structures to build the trees. Good luck.

sd cards

No comments:

Post a Comment