11,707,167 members (49,176 online)

# Create Postfix from infix experssion.

, 19 Aug 2006 52.1K 835 15
 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

## About the Author

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

## Comments and Discussions

 View All Threads First Prev Next
 WATCH OUT! This solution is wrong!! Member 451662817-Mar-08 13:14 Member 4516628 17-Mar-08 13:14
 Re: WATCH OUT! This solution is wrong!! ali_reza_zareian18-Mar-08 9:14 ali_reza_zareian 18-Mar-08 9:14
 Re: WATCH OUT! This solution is wrong!! PKokkula27-Jul-09 2:16 PKokkula 27-Jul-09 2:16
 Last Visit: 31-Dec-99 18:00     Last Update: 30-Aug-15 12:58 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Rant    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.150819.1 | Last Updated 20 Aug 2006
Article Copyright 2006 by ali_reza_zareian
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid