Thread: Infix to postfix

  1. #1
    Liberty4all
    Guest

    Infix to postfix

    Hey everyone!
    I'm looking for an algoritem which converts an infix squence to postfix. My problem is that I don't know what to do with the brackets in the squence. Here's what I have so far...

    counter=0
    init(stack)
    While not end of line
    read x
    if x is a number
    print x
    counter++
    else //x is an oprenad
    push(stack,x)
    if counter==2
    y=pop(stack)
    print y
    counter=0
    while not_empty(stack)
    y=pop(stack)
    print y

    I believe this would work if converted into code. How do I make it work if the expression contains brackets? i dont want the output to have any brackets in it

    I would appreciate any help you could offer, and no code is needed (just an algoritem).

    Thanks

  2. #2
    Liberty4all
    Guest
    argh why can't i post spaces?

    Hey everyone!
    I'm looking for an algoritem which converts an infix squence to postfix. My problem is that I don't know what to do with the brackets in the squence. Here's what I have so far...
    BEGIN
    counter=0
    init(stack)
    While not end of line
    {read x
    if x is a number
    {print x
    counter++}
    else //x is an oprenad
    {push(stack,x)}
    if counter==2
    {y=pop(stack)
    print y
    counter=0}
    }
    while not_empty(stack)
    {y=pop(stack)
    print y}
    END

    I hope it's clearer now....

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Dont cross post please.

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, 08: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, 08:46 AM