0% found this document useful (0 votes)
12 views33 pages

Postfix Calculations

The document describes how to evaluate postfix expressions. It explains that one scans the expression from left to right. If a character is a digit, it is pushed onto the stack. If a character is an operator, the two values at the top of the stack are popped and the operation is performed, with the result pushed back onto the stack. After scanning the entire expression, the final value on the stack is the result.

Uploaded by

Dr. VASAVI BANDE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views33 pages

Postfix Calculations

The document describes how to evaluate postfix expressions. It explains that one scans the expression from left to right. If a character is a digit, it is pushed onto the stack. If a character is an operator, the two values at the top of the stack are popped and the operation is performed, with the result pushed back onto the stack. After scanning the entire expression, the final value on the stack is the result.

Uploaded by

Dr. VASAVI BANDE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

postfix calculations

Scan the postfix expression left to right

 If the character x is a digit


 Push it into the stack
 if the character is an operator (+,-,*,/)
 pop two values from the stack
 Perform the operation
 Push the result of the operation into the stack

When all characters in postfix expression are processed pop the


value from the stack and output it.
postfix calculation
Stack
Postfix Expression
6523+8*+3+*

=
postfix calculation
Stack
Postfix Expression
523+8*+3+*

=

6
postfix calculation
Stack
Postfix Expression
23+8*+3+*

5
6
postfix calculation
Stack
Postfix Expression
3+8*+3+*

2 =
5
6
postfix calculation
Stack
Postfix Expression
+8*+3+*

3
2 =
5
6
postfix calculation
Stack
Postfix Expression

8*+3+*

3
2 +=
5
6
postfix calculation
Stack
Postfix Expression
8*+3+*

2 +3=
-5
(6
postfix calculations
Stack
Postfix Expression
8*+3+*

2+3=

-5
(6
postfix calculations
Stack
Postfix Expression
8
d *– +( e3 + f* )

a
2b++
3 c= -5

-5
*(6
postfix calculations
Stack
Postfix Expression
8
– *( e
++3 f+)*

a
b + c= -d
5
-5
*(6
postfix calculations
Stack
Postfix Expression
*–
(e+( e
3+
+ f )f* )

8
a
b + c= -–dd *
5
-5
-*(6
postfix calculations
Stack
Postfix Expression
+
e
– (3 e
( e+ ++ f*)f )
f )+

8
a
b* + =c 
-– dd *
5
(-5
-*(6
postfix calculations
Stack
Postfix Expression
+
( e(3
– +++
f )e f*)f )

a
b* 8+ =c 
-– dd * e
5
(-5
-*(6
postfix calculations
Stack
Postfix Expression
+( )e(3 e
f– +++
f*)f )

+ a
5b* 8+ =c -– dd * e
(-5
-*(6
postfix calculations
Stack
Postfix Expression
+( e(3 e
)– +++
f*)f )

+ a
5b* 8+ =c 40
-– dd * e f

(-5
-*(6
postfix calculations
Stack
Postfix Expression
+
( e(3 e
– +++
f*)f )

a
b + c= -–dd * e f +
40
-5
-*(6
postfix calculations
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a
b++
 c= -–dd * e f + -
40
-5
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a
b++
40c =-– dd * e f +

-5
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a
5b++
40c =-– d
d * e f +

-
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a
5b++
40c =-– d
d*ef+
45

-
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a b+c=-–dd * e f +

-45
18
-*(6
Stack
Postfix Expression
+
3
( e+
– (* e
+* +
f )f )

a b+c=-–dd * e f +
3
-45
18
-*(6
Stack
Postfix Expression
*–
3( e+
(e+* +
f )f )

a b++c=-–dd * e f +
3
-45
18
-*(6
Stack
Postfix Expression
*–
3( e+
(e+* +
f )f )

a b++3 c=-–dd * e f +

-45
18
-*(6
Stack
Postfix Expression
*–
3( e+
(e+* +
f )f )

-– d
a45b + 3c = d*ef+

-18
-*(6
Stack
Postfix Expression
*–
3( e+
(e+* +
f )f )

a45b + 3c =
-– d48
d*ef+

-18
-*(6
Stack
Postfix Expression
*–
3( e+
(e+* +
f )f )

a b+c =-– d
d * e f +

-18
48
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a b* +c=-–dd * e f +

-18
48
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a b* +48
c -–=dd * e f +

-18
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a6 b* +48 =dd * e f +
c -–

-18
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a6 b* +48
c -–
=dd288
*ef+

-18
-*(6
Stack
Postfix Expression
3
( e+
– (e+* +
f )f )

a b+c=-–dd * e f +

-18
*-(6
288

You might also like