Click here to Skip to main content
Licence 
First Posted 19 Aug 2006
Views 42,742
Bookmarked 15 times

Create Postfix from infix experssion.

By | 19 Aug 2006 | Article
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?

 

 (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

About the Author

ali_reza_zareian

Software Developer

Iran (Islamic Republic Of) Iran (Islamic Republic Of)

Member

Where is the truth?

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberMohamad K Ayash11:30 3 Oct '09  
GeneralIncorrect Solution Pinmembernaeem_libra19:50 8 Dec '08  
GeneralRe: Incorrect Solution Pinmemberali_reza_zareian7:24 21 Jan '09  
Generalhelp me i am not getting proper out put for infix to post evaln(main problem in evaluvation) Pinmemberkarthikragunath8719:05 12 Aug '08  
GeneralBetter method PinmemberPIEBALDconsult17:26 11 Jun '08  
GeneralWATCH OUT! This solution is wrong!! PinmemberMember 451662813:14 17 Mar '08  
GeneralRe: WATCH OUT! This solution is wrong!! Pinmemberali_reza_zareian9:14 18 Mar '08  
GeneralRe: WATCH OUT! This solution is wrong!! PinmemberPKokkula2:16 27 Jul '09  
Generalplz help me Pinsussbehruoz guozali asl7:01 8 Dec '07  
AnswerRe: plz help me Pinmemberali_reza_zareian7:07 21 Jan '09  
Generalprecedence logic is missing PinmemberSoftwareCat5:11 17 May '07  
QuestionGood? Pinmemberazam's19:03 25 Feb '07  
GeneralDon't meant to complain but... PinmemberHerbert Sauro19:41 21 Aug '06  

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.

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