infix to postfix

need help with the concept of it

Page 1 of 1

3 Replies - 1594 Views - Last Post: 12 February 2010 - 04:37 PM Rate Topic: -----

#1 hardwired002  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • 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

please?
thanks
Is This A Good Question/Topic? 0
  • +

Replies To: infix to postfix

#2 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 540
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 hardwired002  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • 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 :D

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)
Was This Post Helpful? 0
  • +
  • -

#4 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 857
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1