infix to postfix

This is a discussion on infix to postfix within the C++ Programming forums, part of the General Programming Boards category; i have an string : (3+5) * (20/4) i have to convert this string to 3 5 + 20 4 ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    infix to postfix

    i have an string : (3+5) * (20/4)
    i have to convert this string to 3 5 + 20 4 / * (to postfix form)
    i cant do this can you tell me how can i do this

  2. #2
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    Put the infix expression into a binary tree where the node is the operator and the left and right subtrees are what is being operated on.

    To convert this to postfix, use recursion

    postfix(tree T){

    if(leftsubtree == null && rightsubtree == null){
    print node;
    return;
    }


    if(leftsubtree != null) postfix(leftsubtree);

    i(rightsubtree != null) postfix(rightsubtree);

    print node;

    }

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    There are a few references on the internet that do this. I wrote my own infix to postfix (in C not C++) and it used a stack which had values and operators pushed and popped off the stack is needed. The code may be a bit hard to read (I often don't comment my little ventures) but if you want it as a reference send me a PM.

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. Infix, Postfix, Pseudo-Calculator using Stack ADT
    By sangken in forum C Programming
    Replies: 9
    Last Post: 09-08-2006, 09:17 AM
  3. Replies: 4
    Last Post: 03-12-2006, 02:17 PM
  4. Converting from infix to postfix
    By jcramer in forum C Programming
    Replies: 4
    Last Post: 03-27-2004, 09:23 PM
  5. Infix to Postfix
    By dat in forum C Programming
    Replies: 6
    Last Post: 06-16-2003, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21