Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the inversion of the Shunting Yard algorithm?

Dijkstra's Shunting Yard algorithm is used to parse an infix notation and generate RPN output.

I am looking for the opposite, a way to turn RPN into highschool-math-class style infix notation, in order to represent RPN expressions from a database to lay users in an understandable way.

Please save your time and don't cook up the algorithm yourselves, just point me to textbook examples that I can't seem to find. Working backwards from the Shunting Yard algorithm and using my knowledge about the notations I'll probably be able to work up a solution. I'm just looking for a quick shortcut, so I don't have to reinvent the wheel.

Oh, and please don't tag this as "homework", I swear I'm out of school already! ;-)

like image 885
Hanno Fietz Avatar asked Sep 17 '08 19:09

Hanno Fietz


1 Answers

Since RPN is also known as postfix notation, I tried googling convert "postfix to infix" and got quite a few results. The first several have code examples, but I found the RubyQuiz entry particularly enlightening.

like image 163
Bill the Lizard Avatar answered Oct 24 '22 06:10

Bill the Lizard