# infix to postfix

Page 1 of 1

## 3 Replies - 1845 Views - Last Post: 12 February 2010 - 04:37 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=155622&amp;s=c69f5e0439289da89beef2fd66067f71&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hardwired002

Reputation: 0
• Posts: 62
• Joined: 05-February 10

# infix to postfix

Posted 12 February 2010 - 09:50 AM

hi guys
so i want help with the concept or idea behind it
using stacks, pop,push,retrieve

can you guys, tell me the concept behind it?
or just the basic idea of it
and after i come to understand how it must work, ill post some codes

thanks
Is This A Good Question/Topic? 0

## Replies To: infix to postfix

### #2 Martyn.Rae

• The programming dinosaur

Reputation: 542
• Posts: 1,406
• Joined: 22-August 09

## Re: infix to postfix

Posted 12 February 2010 - 09:55 AM

This has probably been posted in the wrong forum!

Infix notation is what we normally use to write down mathematical formula such as 2 + 5. Postfix notation would be 2 5 +. Seen from a computer perspective, infix notation is not very easy to handle, whereas 2 5 + can be accommodated using a stack.

1. Push 2
2. Push 5
3. + (pop 5 pop 2 and add together)

Some programming languages expect their input in postfix notation. FORTH being a prime example.

Hope that helps.

This post has been edited by Martyn.Rae: 12 February 2010 - 09:56 AM

### #3 hardwired002

Reputation: 0
• Posts: 62
• Joined: 05-February 10

## Re: infix to postfix

Posted 12 February 2010 - 04:20 PM

thanks martyn!

im coding this in C++ so i thought this is the right subforum

what i wanted is the idea of a program that

1. reads an input of string (infix)
2. converts that string to postfix (without operating on it)

### #4 Bench

• D.I.C Lover

Reputation: 859
• Posts: 2,343
• Joined: 20-August 07

## Re: infix to postfix

Posted 12 February 2010 - 04:37 PM

Reading the input shouldn't pose too much of a problem - the C++ string and stringstream libraries should be able to help you split a string into tokens (operators/operands)

Take a look at Dijkstra's shunting yard algorithm for the conversion
http://en.wikipedia....-yard_algorithm

It might help to set up a mapping between operators and their precedence - remember that parenthesis are not part of postfix syntax, so they're a special case.

as for stacks, the C++ <stack> library will do everything you need - save you writing your own.

This post has been edited by Bench: 12 February 2010 - 04:40 PM