11,482,402 members (76,816 online)

# Create Postfix from infix experssion.

, 19 Aug 2006 51.6K 832 15
 Rate this:
<!-- 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

}

}

A list of licenses authors might use can be found here

## Share

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

 First Prev Next
 M_k m _k16-Oct-13 8:01 m _k 16-Oct-13 8:01
 My vote of 1 Mohamad K Ayash3-Oct-09 12:30 Mohamad K Ayash 3-Oct-09 12:30
 Very Messy. Lots of typos. Weak content for a very classical problem in a 2nd course in programming.
 Incorrect Solution naeem_libra8-Dec-08 20:50 naeem_libra 8-Dec-08 20:50
 Re: Incorrect Solution ali_reza_zareian21-Jan-09 8:24 ali_reza_zareian 21-Jan-09 8:24
 help me i am not getting proper out put for infix to post evaln(main problem in evaluvation) karthikragunath8712-Aug-08 20:05 karthikragunath87 12-Aug-08 20:05
 Better method PIEBALDconsult11-Jun-08 18:26 PIEBALDconsult 11-Jun-08 18:26
 WATCH OUT! This solution is wrong!! Member 451662817-Mar-08 14:14 Member 4516628 17-Mar-08 14:14
 Re: WATCH OUT! This solution is wrong!! ali_reza_zareian18-Mar-08 10:14 ali_reza_zareian 18-Mar-08 10:14
 Re: WATCH OUT! This solution is wrong!! PKokkula27-Jul-09 3:16 PKokkula 27-Jul-09 3:16
 plz help me behruoz guozali asl8-Dec-07 8:01 behruoz guozali asl 8-Dec-07 8:01
 Re: plz help me ali_reza_zareian21-Jan-09 8:07 ali_reza_zareian 21-Jan-09 8:07
 precedence logic is missing SoftwareCat17-May-07 6:11 SoftwareCat 17-May-07 6:11
 Good? azam's25-Feb-07 20:03 azam's 25-Feb-07 20:03
 Don't meant to complain but... Herbert Sauro21-Aug-06 20:41 Herbert Sauro 21-Aug-06 20:41
 Last Visit: 31-Dec-99 19:00     Last Update: 24-May-15 16:42 Refresh 1