Make Your Search Easy ! :) Use me

Showing posts with label Data Structure. Show all posts
Showing posts with label Data Structure. Show all posts

Thursday, February 23, 2017

Postfix - Infix

Evaluate the given postfix notation of expression :-
6,  5,  2,  *,  10,  4,  +,  +,  -


Symbol Scanned
Operation
Stack
6
Push to Stack
6
5
Push to Stack
6  5
2
Push to Stack
6  5  2
*
Pop 2
Pop 5
5 * 2 = 10
Push 10
6  5
6

6  10
10
Push to Stack
6  10  10
4
Push to Stack
6  10  10  4
+
Pop 4
Pop 10
10 + 4 = 14
Push 14
6  10  10
6  10

6  10  14
+
Pop 14
Pop 10
10 + 14 = 24
Push 24
6  10
6

6  24
-
Pop 24
Pop 6
6 – 24 = -18
Push -18
6


-18
               


Result :                 -18

Postfix - Infix


Change  ( P + Q * ( R - S ) / T ) into postfix expression :-

Symbol Scanned
Operation
Stack
Expression
(
Push to Stack
(

P
Add to Expression
(
P
+
Push to Stack
( +
P
Q
Add to Expression
( +
P Q
*
Push to Stack
( + *
P Q
(
Push to Stack
( + * (
P Q
R
Add to Expression
( + * (
P Q R
-
Push to Stack
( + * ( -
P Q R
S
Add to Expression
( + * ( -
P Q R S
)
Pop ‘-‘
( + *
P Q R S -
/
Push to Stack
Pop ‘*’
( + /
P Q R S - *
T
Add to Expression
( + /
P Q R S - * T
)
Push to Stack
Pop ‘/’ and ‘+’
Empty
P Q R S - * T/ +

Wednesday, February 22, 2017

Postfix - Infix

Evaluate the given postfix equation :-
20,  8,  4,  /,  2,  3,  +,  *,  -


Symbol Scanned
Operation
Stack
20
Push to Stack
20
8
Push to Stack
20  8
4
Push to Stack
20  8  4
/
Pop 4
Pop 8
8/4 = 2
Push 2
20  8
20

20  2
2
Push to Stack
20  2  2
3
Push to Stack
20  2  2  3
+
Pop 3
Pop 2
2 + 3 = 5
Push 5
20  2  2
20  2

20  2  5
*
Pop 5
Pop 2
2 * 5 = 10
Push 10
20  2
20

20  10
-
Pop 10
Pop 20
20 – 10 = 10
Push 10
20


10
               

                Result :                 10

Postfix - Infix

Evaluate the given postfix notation of expression :- 
True, False, AND, True, True, NOT, OR, AND



Symbol Scanned
Operation
Stack
True
Push to Stack
True
False
Push to Stack
True  False
AND
Pop False
Pop True
False AND True = False
Push Flase
True


False
True
Push to Stack
False  True
True
Push to Stack
 False  True  True
NOT
Pop True
NOT True = False
Push False
False  True

False  True  False
OR
Pop False
Pop True
False OR True = True
Push True
False  True
False

False  True
AND
Pop True
Pop False
True AND False = False
Push Flase
False


False
               


                Result :                 False