Click here to Skip to main content
Click here to Skip to main content

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

Introduction

Ali reza zareian.

This is a simple program that creates postfix expression from an infix expression. What is an infix expression?

 

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

Add a with b at the first time then divided with d.

If  we change this expression to postfix. We have this one ab+d/.

What is the useful of postfix?

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

 

What is this program?

 This programe use a simple algoritm to change infix to postfix.Just sees the example

Before I should say I use stack in this program.

 

Infix Program =(a+b)/d 

 

 

Input     Stack        output

(             (

a            (                     a

+           (+                   a

b           (+                   ab

)                                  ab+

/            /                     ab+

d                                 ab+d

No         empty           ab+d/

 

  

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.

 

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

}

 

}

  

 

 

 

 

 

 

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

Share

About the Author

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

Comments and Discussions

 
GeneralM_k Pinmemberm _k16-Oct-13 8:01 
GeneralMy vote of 1 PinmemberMohamad K Ayash3-Oct-09 12:30 
GeneralIncorrect Solution Pinmembernaeem_libra8-Dec-08 20:50 
GeneralRe: Incorrect Solution Pinmemberali_reza_zareian21-Jan-09 8:24 
Generalhelp me i am not getting proper out put for infix to post evaln(main problem in evaluvation) Pinmemberkarthikragunath8712-Aug-08 20:05 
GeneralBetter method PinmemberPIEBALDconsult11-Jun-08 18:26 
GeneralWATCH OUT! This solution is wrong!! PinmemberMember 451662817-Mar-08 14:14 
GeneralRe: WATCH OUT! This solution is wrong!! Pinmemberali_reza_zareian18-Mar-08 10:14 
GeneralRe: WATCH OUT! This solution is wrong!! PinmemberPKokkula27-Jul-09 3:16 
Generalplz help me Pinsussbehruoz guozali asl8-Dec-07 8:01 
???? ????? ???? ??????? ???????? ???? ?? ????? ????? ???? ?? ?? ????
????? ?????? ?????
infix to postfix
?? ????
c++
???????? ????
?? ????
Smile | :)
AnswerRe: plz help me Pinmemberali_reza_zareian21-Jan-09 8:07 
Generalprecedence logic is missing PinmemberSoftwareCat17-May-07 6:11 
QuestionGood? Pinmemberazam's25-Feb-07 20:03 
GeneralDon't meant to complain but... PinmemberHerbert Sauro21-Aug-06 20:41 

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

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

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