Click here to Skip to main content
13,352,879 members (43,694 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 19 Aug 2006

Create Postfix from infix experssion.

, 19 Aug 2006
Rate this:
Please Sign up or sign in to vote.
this article create postfix experssion from an infix experssion.
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->


Ali reza zareian.

This is a simple program that creates postfix expression from an infix expression. What is an infix expression?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>


 (a+b)/d is a simple one. The infix expression is regular for mathematic. it means when u want to calculate this u must<o:p>

Add a with b at the first time then divided with d.<o:p>

If  we change this expression to postfix. We have this one ab+d/.<o:p>

What is the useful of postfix?<o:p>

 At first we don't need parantes.Second we can write a program to calculate this expression easier than infix expression.<o:p>


What is this program?<o:p>

 This programe use a simple algoritm to change infix to postfix.Just sees the example<o:p>

Before I should say I use stack in this program.<o:p>


Infix Program =(a+b)/d  <o:p>



Input     Stack        output<o:p>

(             (<o:p>

a            (                     a<o:p>

+           (+                   a<o:p>

b           (+                   ab<o:p>

)                                  ab+<o:p>

/            /                     ab+<o:p>

d                                 ab+d<o:p>

No         empty           ab+d/<o:p>



Main method of this program!?

1)      private int isOperand(char  chrTemp);

2)      private int isOperator(char chrTemp);

3)      public string createPrifex();



1) isOperand check character if they are in this set.{'*','/','+','-','^','('}

      If true we add this character to stack.


2)isOperator check character if they are in this set.{'*','/','+','-','^'}

    This  method check the  stack  and  pop all the operator except '('.


3)createPrifix method create postfix from infix use isOperand and isOperator.




 For (the first infix character ) to  last character


   If  (is operand)   add to stack


   If  (it is ')' )   pop  stack and send it to output

Else send other character to output












This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
Where is the truth?

You may also be interested in...


Comments and Discussions

GeneralIncorrect Solution Pin
naeem_libra8-Dec-08 20:50
membernaeem_libra8-Dec-08 20:50 
GeneralRe: Incorrect Solution Pin
ali_reza_zareian21-Jan-09 8:24
memberali_reza_zareian21-Jan-09 8:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 20 Aug 2006
Article Copyright 2006 by ali_reza_zareian
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid