Thread: Algorithm help on converting infix expression to postfix

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Algorithm help on converting infix expression to postfix

    I found numerous examples on converting infix expression to postfix expression but my program needs to include some functions like sqrt(x), min/max(x,y), fact(x), abs(x).

    abs(‐5) is converted to ‐5 abs
    120 – (45+3) is converted to 120 45 3 + ‐
    (3^2 + 4^5)*fact(3) is converted to 3 2 ^ 4 5 ^ + 3 fact *
    min(3‐(4‐7) , (2+4)/3) is converted to 3 4 7 ‐ ‐ 2 4 + 3 / min

    I'm confused about what the precedence of those functions needs to be.

    Thanks for your input!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Precedence is not a problem. Read up on Reverse Polish Notation on Wikipedia. Using a small array as a first in, last out stack, it all comes up roses.

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Take a look at shunting yard algorithm.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 07:44 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 4
    Last Post: 03-12-2006, 02:17 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Converting from infix to postfix
    By jcramer in forum C Programming
    Replies: 4
    Last Post: 03-27-2004, 09:23 PM