SlideShare a Scribd company logo
DATA STRUCTURES
ASSIGNMENT # 2
“Infix to Prefix Conversion, Evaluation and Pseudo code”
SUBMITTED TO:
Zaheer Sani
SUBMITTED BY:
Ahmed Khateeb
SP12-BCS-028
BSCS – IIIC
Department of Computer Science
A) CONVERSION INFIX EXPRESSION TO PREFIX.
B) EVALUATION OF INFIX EXPRESSION (AND VERIFICATION).
C) PSEUDO CODE TO CONVERT INFIX TO PREFIX
PART A
- Let have an Infix Expression
( (A+B) * (C+D) / (E-F) ) + G
- Reading Expression from “right to left” character by
character.
- We have Input, Prefix_Stack & Stack.
- Now converting this expression to Prefix.
Input Prefix_Stack Stack
G G (empty)
+ G +
) G + )
) G + ) )
F GF + ) )
- GF + ) ) -
E GFE + ) ) -
( GFE- + )
/ GFE- + ) /
) GFE- + ) / )
D GFE-D + ) / )
+ GFE-D + ) / ) +
C GFE-DC + ) / ) +
( GFE-DC+ + ) /
* GFE-DC+ + ) / *
) GFE-DC+ + ) / * )
B GFE-DC+B + ) / * )
+ GFE-DC+B + ) / * ) +
A GFE-DC+BA + ) / * ) +
( GFE-DC+BA+ + ) / *
( GFE-DC+BA+*/ +
(empty) GFE-DC+BA+*/+ (empty)
- Now pop-out Prefix_Stack to output (or simply reverse).
Prefix expression is
+ / * + A B + C D – E F G
PART B
- First I’m assigning values to all operands.
A = 14
B = 12
C = 10
D = 8
E = 6
F = 4
G = 2
- Evaluating Infix expression using above values.
( (14+12) * (10+8) / (6-4) ) + 2
( 26 * 18 / 2 ) + 2
( 468 / 2 ) + 2
( 234 ) + 2
236
- Evaluating Infix expression using above values.
+ / * + 14 12 + 10 8 - 6 4 2 (14+2 & 10+8 & 6-4)
+ / * 26 18 2 2 (26 * 18)
+ / 468 2 2 (468 / 2)
+ 234 2 (234 + 2)
236
- Both are same, so our conversion is correct!
PART C
Arr = (Infix Expression)
Set loop_counter to length_ of_ Arr
do
character = arr[loop_counter]
if character is operator
push character to prefix_stack
if character is ‘)’
push character to stack
if character is ‘(’
do
pop character and push it to prefix_stack
until character equals ‘(‘
if character is operator
if character_precedence is greater OR is equal to stack[top]_ precedence
push to stack
else
do
pop from stack and push to prefix_stack
until condition satisfices
loop_counter = loop_counter - 1
While loop_counter IS NOT EQUAL to 0
Pop out prefix_stack and display each element
Ad

More Related Content

What's hot (20)

Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Self-Employed
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
 
C pointers
C pointersC pointers
C pointers
Aravind Mohan
 
Conversion from infix to prefix using stack
Conversion from infix to prefix using stackConversion from infix to prefix using stack
Conversion from infix to prefix using stack
Haqnawaz Ch
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
Bhavesh Sanghvi
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Make Mannan
 
Stack
StackStack
Stack
Zaid Shabbir
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
Emertxe Information Technologies Pvt Ltd
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
SIVASHANKARIRAJAN
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
Digvijay Singh Karakoti
 
Stack
StackStack
Stack
Seema Sharma
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
Praveen M Jigajinni
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
junnubabu
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
Praveen Vishwakarma
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Self-Employed
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
 
Conversion from infix to prefix using stack
Conversion from infix to prefix using stackConversion from infix to prefix using stack
Conversion from infix to prefix using stack
Haqnawaz Ch
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Make Mannan
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
junnubabu
 

Similar to Infix to Prefix (Conversion, Evaluation, Code) (20)

2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
Senthil Kumar
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
Junaid Ahmed
 
1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf
soniasharmafdp
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
Kho コー。イエー。イエン
 
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptxData Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
RashidFaridChishti
 
Application of Stacks
Application of StacksApplication of Stacks
Application of Stacks
Ain-ul-Moiz Khawaja
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
ranaibrahim453
 
week9-prefixinfixandpostfixnotations-191013065821.pptx
week9-prefixinfixandpostfixnotations-191013065821.pptxweek9-prefixinfixandpostfixnotations-191013065821.pptx
week9-prefixinfixandpostfixnotations-191013065821.pptx
ssusere3b1a2
 
STACK Applications in DS
STACK Applications in DSSTACK Applications in DS
STACK Applications in DS
NARESH GUMMAGUTTA
 
program 4.doc in computer science and engineering
program 4.doc in computer science and engineeringprogram 4.doc in computer science and engineering
program 4.doc in computer science and engineering
SUNITHAS81
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
Kho コー。イエー。イエン
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
mailmerk
 
Applications of Stack
Applications of StackApplications of Stack
Applications of Stack
Christalin Nelson
 
data structure and algorithm by bomboat_3
data structure and algorithm by bomboat_3data structure and algorithm by bomboat_3
data structure and algorithm by bomboat_3
jateno3396
 
Please need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdfPlease need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdf
pristiegee
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
OliverKane3
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
OliverKane3
 
Data Structure and Algorithms by Sabeen Memon03.pptx
Data Structure and Algorithms by Sabeen Memon03.pptxData Structure and Algorithms by Sabeen Memon03.pptx
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
Senthil Kumar
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
Junaid Ahmed
 
1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf
soniasharmafdp
 
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptxData Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
RashidFaridChishti
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
ranaibrahim453
 
week9-prefixinfixandpostfixnotations-191013065821.pptx
week9-prefixinfixandpostfixnotations-191013065821.pptxweek9-prefixinfixandpostfixnotations-191013065821.pptx
week9-prefixinfixandpostfixnotations-191013065821.pptx
ssusere3b1a2
 
program 4.doc in computer science and engineering
program 4.doc in computer science and engineeringprogram 4.doc in computer science and engineering
program 4.doc in computer science and engineering
SUNITHAS81
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
mailmerk
 
data structure and algorithm by bomboat_3
data structure and algorithm by bomboat_3data structure and algorithm by bomboat_3
data structure and algorithm by bomboat_3
jateno3396
 
Please need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdfPlease need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdf
pristiegee
 
Data Structure and Algorithms by Sabeen Memon03.pptx
Data Structure and Algorithms by Sabeen Memon03.pptxData Structure and Algorithms by Sabeen Memon03.pptx
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
Ad

Recently uploaded (20)

Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Open Access: Revamping Library Learning Resources.
Open Access: Revamping Library Learning Resources.Open Access: Revamping Library Learning Resources.
Open Access: Revamping Library Learning Resources.
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Ad

Infix to Prefix (Conversion, Evaluation, Code)

  • 1. DATA STRUCTURES ASSIGNMENT # 2 “Infix to Prefix Conversion, Evaluation and Pseudo code” SUBMITTED TO: Zaheer Sani SUBMITTED BY: Ahmed Khateeb SP12-BCS-028 BSCS – IIIC Department of Computer Science
  • 2. A) CONVERSION INFIX EXPRESSION TO PREFIX. B) EVALUATION OF INFIX EXPRESSION (AND VERIFICATION). C) PSEUDO CODE TO CONVERT INFIX TO PREFIX PART A - Let have an Infix Expression ( (A+B) * (C+D) / (E-F) ) + G - Reading Expression from “right to left” character by character. - We have Input, Prefix_Stack & Stack. - Now converting this expression to Prefix. Input Prefix_Stack Stack G G (empty) + G + ) G + ) ) G + ) ) F GF + ) ) - GF + ) ) - E GFE + ) ) - ( GFE- + ) / GFE- + ) / ) GFE- + ) / ) D GFE-D + ) / ) + GFE-D + ) / ) + C GFE-DC + ) / ) +
  • 3. ( GFE-DC+ + ) / * GFE-DC+ + ) / * ) GFE-DC+ + ) / * ) B GFE-DC+B + ) / * ) + GFE-DC+B + ) / * ) + A GFE-DC+BA + ) / * ) + ( GFE-DC+BA+ + ) / * ( GFE-DC+BA+*/ + (empty) GFE-DC+BA+*/+ (empty) - Now pop-out Prefix_Stack to output (or simply reverse). Prefix expression is + / * + A B + C D – E F G PART B
  • 4. - First I’m assigning values to all operands. A = 14 B = 12 C = 10 D = 8 E = 6 F = 4 G = 2 - Evaluating Infix expression using above values. ( (14+12) * (10+8) / (6-4) ) + 2 ( 26 * 18 / 2 ) + 2 ( 468 / 2 ) + 2 ( 234 ) + 2 236 - Evaluating Infix expression using above values. + / * + 14 12 + 10 8 - 6 4 2 (14+2 & 10+8 & 6-4) + / * 26 18 2 2 (26 * 18) + / 468 2 2 (468 / 2) + 234 2 (234 + 2) 236 - Both are same, so our conversion is correct! PART C
  • 5. Arr = (Infix Expression) Set loop_counter to length_ of_ Arr do character = arr[loop_counter] if character is operator push character to prefix_stack if character is ‘)’ push character to stack if character is ‘(’ do pop character and push it to prefix_stack until character equals ‘(‘ if character is operator if character_precedence is greater OR is equal to stack[top]_ precedence push to stack else do pop from stack and push to prefix_stack until condition satisfices loop_counter = loop_counter - 1 While loop_counter IS NOT EQUAL to 0 Pop out prefix_stack and display each element