Question

Convert the following infix expression to A) postfix B) prefix 3 * 4 / ( 5...

Convert the following infix expression to A) postfix B) prefix

3 * 4 / ( 5 - 6 * 7 )

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Move Current Token Stack Output
1 3 empty 3
2 * * 3
3. 4 * 3 4
4 / / 3 4 *
5 ( (/ 3 4 *
6 5 (/ 3 4 * 5
7 - -(/ 3 4 * 5
8 6 -(/ 3 4 * 5 6
9 * *-(/ 3 4 * 5 6
10 7 *-(/ 3 4 * 5 6 7
11 ) / 3 4 * 5 6 7 * -
12 empty 3 4 * 5 6 7 * - /

So,

a) Postfix

3 4 * 5 6 7 * - /

b) Prefix

For converting to prefix, reverse infix expression, then convert to postfix and reverse postfix.

Reversed infix

(7* 6 - 5 ) / 4 * 3

Convert to postfix

Move Current Token Stack Output
1 ( (
2 7 ( 7
3. * *( 7
4 6 *( 7 6
5 - -( 7 6 *
6 5 -( 7 6 * 5
7 ) 7 6 * 5 -
8 / / 7 6 * 5 -
9 4 / 7 6 * 5 - 4
10 * */ 7 6 * 5 - 4
11 3 */ 7 6 * 5 - 4 3
12 empty 7 6 * 5 - 4 3 * /

Reverse postfix

/ * 3 4 - 5 * 6 7

So, the prefix is

/ * 3 4 - 5 * 6 7

Add a comment
Know the answer?
Add Answer to:
Convert the following infix expression to A) postfix B) prefix 3 * 4 / ( 5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT