01-04-2012, 10:16 PM
The algorithm to convert infix to postfix is given on page 71 in handouts.
In simple words,
if operand:
write in postfix string.
if operator:
if top of stack has more precedence than this operator
pop top of stack and append in postfix string. Continue until false. push new operator on stack
else if top of stack has less precedence than this operator
push it on stack
So, for the infix expression:
3 + 5 * 6 - 7 * ( 8 + 5)
Symbol
Postfix
Stack
3
3
+
3
+
5
3 5
+
*
3 5
*
+
6
3 5 6
*
+
-
3 5 6 *
-
+
7
3 5 6 * 7
-
+
*
3 5 6 * 7
*
-
+
(
3 5 6 * 7
(
*
-
+
8
3 5 6 * 7 8
(
*
-
+
+
3 5 6 * 7 8
+
(
*
-
+
5
3 5 6 * 7 8 5
+
(
*
-
+
)
3 5 6 * 7 8 5 +
*
-
+
3 5 6 * 7 8 5 + * - +
In simple words,
if operand:
write in postfix string.
if operator:
if top of stack has more precedence than this operator
pop top of stack and append in postfix string. Continue until false. push new operator on stack
else if top of stack has less precedence than this operator
push it on stack
So, for the infix expression:
3 + 5 * 6 - 7 * ( 8 + 5)
Symbol
Postfix
Stack
3
3
+
3
+
5
3 5
+
*
3 5
*
+
6
3 5 6
*
+
-
3 5 6 *
-
+
7
3 5 6 * 7
-
+
*
3 5 6 * 7
*
-
+
(
3 5 6 * 7
(
*
-
+
8
3 5 6 * 7 8
(
*
-
+
+
3 5 6 * 7 8
+
(
*
-
+
5
3 5 6 * 7 8 5
+
(
*
-
+
)
3 5 6 * 7 8 5 +
*
-
+
3 5 6 * 7 8 5 + * - +
0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
