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>