Google Answers Logo
View Question
Q: postfix to infix ( Answered,   0 Comments )
Subject: postfix to infix
Category: Miscellaneous
Asked by: joao-ga
List Price: $2.00
Posted: 16 Sep 2002 04:28 PDT
Expires: 16 Oct 2002 04:28 PDT
Question ID: 65507
program that converts a postfix expression to infix, using a pushdown stack
Subject: Re: postfix to infix
Answered By: dogbite-ga on 18 Sep 2002 20:40 PDT
You want a program to convert something like

   ( 3 ( 4 2 + ) 5 * )


   ( ( 3 * ( 4 + 2 ) ) * 5 )

Suppose you have a list of tokens ('(', numbers, operators, ')')
as the programs input.  The algorithm is:

if [token is '('] then
  push '(' on the stack

else if [token is number] then
  push number on the stack

else if [token is operator] then
    pop off two elements a,b
    if top element on stack is '(' then
      pop off the '('
      push back on "(a operator b)"   
      break while
      push back on "(a operator b)"
  end while

else if [token is ')'] then
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy