File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Infix to Postfix conversion. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Infix to Postfix conversion." Watch "Infix to Postfix conversion." New topic
Author

Infix to Postfix conversion.

Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 35

Hi All,

I have string "(1+2*3/4+7)". Now I want to postfix it and store the result on the stack for further calculation.


~R@njeet.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

What stack? What result? Please be a bit more clear.

Also, show us what you've tried so far.
Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 35



And the output is :- [(, 1, +, 2, *, 3, /, 4, +, 7, )]

Now I want to calculate the answer. For this I think doing postfix is more suitable. If anyone have better idea then please mention it.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8414
    
  23

Ranjeet Deshmukh wrote:And the output is :- [(, 1, +, 2, *, 3, /, 4, +, 7, )
Now I want to calculate the answer. For this I think doing postfix is more suitable.

Well postfix (or RPN) is definitely the easiest to deal with; but all you've done so far is convert String.toCharArray() to a Stack, which isn't likely to help you much.

Also: What about values that have more than one digit?

My advice: Split your String up into proper operators; and then have a look at the Shunting-yard algorithm.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Infix to Postfix conversion.