I am trying to take an infix expression such as a + b + c and turn it to postfix ab+c+ and prefix ++abc. I need to push them on the stack etc. While I worked out a method for stack pushing It depends on whether or not the operator is of a higher presidence or not than that one already on the top of the stack. The problem is that I don't know how to in JAVA compare operators. I did find some stuff such as this:
StackB x = new StackB ();
String op = "+-*/%^";
String post = "";
I wonder about the line:
String op = "+-*/%^";
Are they somehow using this so that the presidence is tested from left to right? Where they somehow make it so that + and - are equal and *, /, and % are equal? so for example since * is more to the right than + it has a higher presedence, again while somehow setting an equality between some of them, (+ and -, and *, /, and %). Does anyone have any idea how to distinguish between the presedences in JAVA?
Thanks,
Brian
In JAVA I want to create a Postfix and Prefix from an infix, but how do I tell JAVA to compare operators?
Operator precedence are already defined in java ...
surf through the link below ,this may help you
http://books.google.com/books?id=saj_wnV...
go to the page no 96-97-98 of this book
try to store all d operators in an array rather then a string ......
local florist
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment