Notices
Results 1 to 3 of 3

Thread: Prefix and postfix notation

  1. #1 Prefix and postfix notation 
    New Member
    Join Date
    Apr 2009
    Posts
    1
    Hi,

    could someone help me with converting expression from prefix into postfix notation? The expression is long and it would be most helpful if someone could share the algorithm for converting between prefix, infix and postfix and propose a solution for the one below. I tried using expression tree but ended up nowhere.

    The expression is: + / * A + B C + A B ^ - * A B C 2

    Thanks!


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Masters Degree Numsgil's Avatar
    Join Date
    Jan 2009
    Posts
    708
    I'm going to assume this is homework, and so proceed carefully.

    First, you understand infix notation and how it works, right? I'll assume you do

    In prefix notation, you have to keep a stack of operations. Basically + * A B C means push addition on the operation stack, then push multiplication on the operation stack. Next you have two numbers, so you can multiply them (A * B). Then you have another number (C), so you can add your numbers (A * B) + C (infix).

    Postfix notation works with more of a numbers stack. The above example would be C B A * + (notice it's reversed). You start by pushing A, B and C onto a numbers stack. Then you use the mult operation to remove two numbers from the stack, multiply them, and push the result back on the stack. Then you use the addition operation to remove two numbers from the stack, and add them. So the final answer is again (A * B) + C (infix).


    Reply With Quote  
     

  4. #3  
    Forum Freshman
    Join Date
    Feb 2009
    Location
    Yangon
    Posts
    9
    The infix notation is

    A*(B+C)/(A+B)+A*B-C^2

    The postfix notation is

    ABC+*AB+/AB*C-2^+
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •