Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
//
2- if(ch>='0'&&ch<='9')
//Check if
the char is number add it to postfix
1- Add postFix +=Character.toString(ch);
3-if(char ='(' )
1-pushStack(char);
4- else if (char=')')
matching '('
pop_char = popStack();
End loop
5-else
1-if (top not Equal -1 And Resulte from
Funcation precedence ( Send arr[top], Send
character of Infix ) Equal True)
1- Set pop_char = popStack();
2-Loop (The Call Funcation precedence
( send pop_char, send character of Infix (ch))
Equal True)
1-Set
postFix +=pop_char;
2-
3-
Set
pop_char = popStack();
End loop
3-
pushStack(ch);
6- else
1pushStack(ch); //Stack is empty or
the operator has precedence
End loop
Algorithm precedence
(OperatorOFtop<char>, OperatorOfInfix
<char >){
This programme check the priority for
operators((,+,-,*,/) and receive parameter
from infixtopostfix program.
1-The first parameter (OperatorOFtop)
come from Stack(array).
2-The second parameter (OperatorOfInfix)
come from an infix expression after
convert it to character
Pre (OperatorOFtop And OperatorOfInfix)
must be initialzed
Post
Nothing
2-
if (precedence1[counter ]==Operator)
1-set
proOfchar=i;
6if(precedence[proOftop]>=precedence[proOf
char])
7-
return true;
8- else return false;
Algorithm EvaluationForPostinfix
(Postinfix<String>){
This programme promt user to inter
Postinfix expression , calculate it and
receive parameter from main application
program.
Pre Postinfix must be initialzed
Post
//
// System.out.println("ch"+ch);
2- if(ch>='0'&&ch<='9')
//Check if
the char is number push it to stack
break;
3-case '-':result=oprator2-oprator1;
//subtract operation for tow number
1- pushStack( (char) result);
2- break;
1-
case
'*':result=oprator1*oprator2;//multiplicati
onoperation for tow number
1- pushStack( (char) result);
2- break;
1-
case
'/':result=oprator2/oprator1; ;//dividing
operation for tow number
break;
default:result=0;
End loop
result=popStack();
return result;
Evaluation
//Return