Click here to Skip to main content
15,860,972 members
Articles / Programming Languages / C#
Article

Create Postfix from infix experssion.

Rate me:
Please Sign up or sign in to vote.
2.67/5 (14 votes)
19 Aug 20062 min read 63.6K   874   15   14
this article create postfix experssion from an infix experssion.

Introduction

Ali reza zareian.

This is a simple program that creates postfix expression from an infix expression. What is an infix expression?<o:p>

<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>

<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>

<o:p> 

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

<o:p> 

<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>

<o:p> 

   <o:p>

Main method of this program!?

1)      private int isOperand(char  chrTemp);

2)      private int isOperator(char chrTemp);

3)      public string createPrifex();

<o:p> 

<o:p> 

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

      If true we add this character to stack.

<o:p> 

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

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

<o:p> 

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

<o:p> 

PesoCode

  

 For (the first infix character ) to  last character

{

   If  (is operand)   add to stack

   Elae

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

Else send other character to output

}

<o:p> 

}

  

<o:p> 

<o:p> 

<o:p> 

<o:p> 

<o:p> 

<o:p> 

License

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


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

Comments and Discussions

 
GeneralM_k Pin
m _k16-Oct-13 7:01
m _k16-Oct-13 7:01 
GeneralMy vote of 1 Pin
Mohamad K. Ayyash3-Oct-09 11:30
Mohamad K. Ayyash3-Oct-09 11:30 
GeneralIncorrect Solution Pin
Libra8528-Dec-08 19:50
Libra8528-Dec-08 19:50 
GeneralRe: Incorrect Solution Pin
ali_reza_zareian21-Jan-09 7:24
ali_reza_zareian21-Jan-09 7:24 
Generalhelp me i am not getting proper out put for infix to post evaln(main problem in evaluvation) Pin
karthikragunath8712-Aug-08 19:05
karthikragunath8712-Aug-08 19:05 
GeneralBetter method Pin
PIEBALDconsult11-Jun-08 17:26
mvePIEBALDconsult11-Jun-08 17:26 
GeneralWATCH OUT! This solution is wrong!! Pin
sudancer17-Mar-08 13:14
sudancer17-Mar-08 13:14 
GeneralRe: WATCH OUT! This solution is wrong!! Pin
ali_reza_zareian18-Mar-08 9:14
ali_reza_zareian18-Mar-08 9:14 
GeneralRe: WATCH OUT! This solution is wrong!! Pin
PKokkula27-Jul-09 2:16
PKokkula27-Jul-09 2:16 
Generalplz help me Pin
behruoz guozali asl8-Dec-07 7:01
sussbehruoz guozali asl8-Dec-07 7:01 
AnswerRe: plz help me Pin
ali_reza_zareian21-Jan-09 7:07
ali_reza_zareian21-Jan-09 7:07 
Generalprecedence logic is missing Pin
SoftwareCat17-May-07 5:11
SoftwareCat17-May-07 5:11 
QuestionGood? Pin
azam's25-Feb-07 19:03
azam's25-Feb-07 19:03 
GeneralDon't meant to complain but... Pin
Herbert Sauro21-Aug-06 19:41
Herbert Sauro21-Aug-06 19:41 

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.