This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Greenhorn

Joined: Jan 18, 2013
Posts: 24

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: 3605
    
  14

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

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

Joined: Jan 18, 2013
Posts: 24



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: 7553
    
  18

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.
 
Similar Threads
i=i++; could anyone explain this....please?
yet another postfix/prefix precedence question
Operator Precedence qstn.
Need explanation for the code
Operators - Mughal p.56 Ques 3.7