0% found this document useful (0 votes)
3 views8 pages

Convert Postfix to Prefix in Python

Uploaded by

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

Convert Postfix to Prefix in Python

Uploaded by

Yash Shekhawat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name:Yash .S.

Shekhawat

Batch:B4

Roll no.:95

Subject DS

Question:

Convert the following postfix expressions into prefix: ABC*+

Implement a python for the same problem

Ans. :

Postfix:

ABC*+

Step-by-Step:-

Step Operation Stack


Read A push A
Read B push A, B
Read C push A, B, C
Read * pop C & B → make *BC A, *BC
Read + pop *BC & A → +A*BC +A*BC

Prefix Expression:-

+A*BC

pg. 1
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

Source code:-

Driver code:-

Output:-

pg. 2
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

pg. 3
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

pg. 4
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

pg. 5
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

pg. 6
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

pg. 7
Name:Yash .S. Shekhawat

Batch:B4

Roll no.:95

Subject DS

pg. 8

You might also like