Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Infix to Postfix conversion.

 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephan van Hulst
Bartender
Pie
Posts: 5810
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What stack? What result? Please be a bit more clear.

Also, show us what you've tried so far.
 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic