Question:

write a program to convert expressions from postfix to prefix

by Guest9670  |  12 years, 7 month(s) ago

0 LIKES UnLike

write a program to convert expressions from postfix to prefix

 Tags: convert, Expressions, postfix, prefix, Program, write

   Report

2 ANSWERS

  1. amomipais82
    Hi,
    check out this site: http://www.cs.man.ac.uk/~pjj/cs212/fix.h

    The best way to think about this is a stack (because this is how computers do equations, using the runtime stack)

    Postfix: 3 4 * 5 7 / -

    The stack will hold numbers, first one in last one out:
    Take the 3, put it in the stack: 3
    Take the 4, put it in the stack (on top of the 3): 3 4

    Things like * - / + can NOT go in the stack, when you run into them you take out the last two numbers put into the stack, first number goes to the right of the expression, second number to the left: 3 * 4 = 12, put 12 in the stack: 12
    Now put the 5 in the stack: 12 5
    Now put the 7 in the stack: 12 5 7
    Now we run into the '/': pop out out the 7 and then the five to give you 5/7 = ~0.71, put 0.71 in the stack: 12 0.71
    Now comes the '-': put out the 0.71, then the 12 and you get 12-0.71

  2. Guest9815
    f*k u
Sign In or Sign Up now to answser this question!

Question Stats

Latest activity: 14 years, 5 month(s) ago.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.