SlideShare ist ein Scribd-Unternehmen logo
1 von 14
PRESENTATION
OF
DATA STRUCTURE & ALGORITHM
BY

Mohammad Saeed Farooqi
 INFIX Notation.
 POSTFIX Notation.
 PREFIX Notation.
 OPERATORS PRECEDENCE.
 Evaluating Of POSTFIX Expression Using Stacks.
 Converting INFIX To POSTFIX Using Stacks.
 ALGORITHMS.



OUTLINES

Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 Infix Expression Are Those In Which Operators Are
Written Between Two Operands.
 Infix Expression Is The Common Arithmetic And
Logical Formula Expression.
 Infix Expression Needs Extra Information To Make The
Order Of Evaluation Of The Operators Clear.
 Rules Built Into The Language About Operator
Precedence And Associativity, And Brackets ( ) To Allow
Users To Override These Rules.

 INFIX EXPRESSION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 EXAMPLE…
 A * ( B + C ) / D…
 This Expression Is Usually Taken To Mean Something
Like: "First Add B And C Together, Then Multiply The
Result By A, Then Divide By D To Give The Final
Answer.

 INFIX EXPRESSION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 POSTFIX Expression Also Known As “Reverse Polish
Expression”
 In These Expressions Operators Are Written After Their
Operands.
 Operators Act On Values Immediately To The Left Of
Them.
 They Do Not Have (Brackets)

 POSTFIX EXPRESSION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 EXAMPLE…
 A B C + * D /…
 Operators Act On Values Immediately To The Left Of
Them.
 For Example, The "+" Above Uses The "B" And "C".
 We Can Add (Totally Unnecessary) Brackets To Make
This Easy.
( (A (B C +) *) D /) .

 POSTFIX EXPRESSION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 Also Known As “Polish Expression”.
 In These Expressions Operators Are Written Before The
Operands.
 We Have To Scan It From Right-To-Left.
 As For Postfix, Operators Are Evaluated Left-To-Right And
Brackets Are Superfluous.
 Operators Act On The Two Nearest Values On The Right.
 I Have Again Added (Totally Unnecessary) Brackets To Make
This Clear.
(/ (* A (+ B C) ) D)
 PREFIX Notation Is Especially Popular With StackBased Operations Due To Its Innate Ability To Easily
Distinguish Order Of Operations Without The Need For
Parentheses.

 PREFIX EXPRESSION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 We Assume The Following Three Levels Of
PRECEDENCE For The Usual Five Binary Operations.
 Highest
Exponentiation ().
 Next Highest Multiplication (*) And Division (/)
Superfluous
 Lowest
Addition (+) And Subtraction (-)
 Without Understanding Operator Precedence You Can
Not Convert Any Expression.

 OPERATOR PRECEDENCE
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
 EVOLUACTION OF POSTFIX EXPRESSION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
• EvaluatePostfix(exp)
• {
• Create A Stack S.
• for I ← 0 to length of the (exp)-1
{
if(exp[i]) // Is An Operand
push(exp[i]);
else if(exp[i])
// Is An Operator
{
op1←pop();
op2← pop();
result←perform(exp[i],op1,op2);
push(result);
}
}
}

 ALGORITHM FOR POSTFIX EVALUATION
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
Converting Infix To Postfix
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
•
•
•
•
•
•
•

Example: 1*2+3.
Scan: *,+ (Stack) And 12 (Postfix Expression).
Precedence Of * Is Higher Than +.
Thus, Append * to postfix Expression.
+ (Stack) And 12* (Postfix Expression ).
Scan Further, + (Stack ) and 12*3 (Postfix Expression)
There Are No Further Operators, Thus, Postfix Is 12*3+

Converting Infix To Postfix
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
Converting Infix To Prefix
Mohammad Saeed Farooqi (University Of Swat, Pakistan)
• Step 1. Push “)” onto STACK, and add “(“ to end of the A.
• Step 2. Scan A from right to left and repeat step 3 to 6 for each element of A
until the STACK is empty.
• Step 3. If an operand is encountered add it to B.
• Step 4. If a right parenthesis is encountered push it onto STACK.
• Step 5. If an operator is encountered then: a. Repeatedly pop from STACK
and add to B each operator (on the top of STACK) which has same or higher
precedence than the operator. b. Add operator to STACK.
• Step 6. If left parenthesis is encontered then a. Repeatedly pop from the
STACK and add to B (each operator on top of stack until a left parenthesis is
encounterd) b. Remove the left parenthesis.
• Step 7. Exit

Converting Infix To Postfix
Mohammad Saeed Farooqi (University Of Swat, Pakistan)

Weitere ähnliche Inhalte

Was ist angesagt?

Stack and queue -polish notations
Stack and queue -polish notationsStack and queue -polish notations
Stack and queue -polish notationsjyoti_lakhani
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluationJeeSa Sultana
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
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 Stacksahil kumar
 
Stack application
Stack applicationStack application
Stack applicationStudent
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaDipayan Sarkar
 

Was ist angesagt? (16)

Stack and queue -polish notations
Stack and queue -polish notationsStack and queue -polish notations
Stack and queue -polish notations
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
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
 
Stack application
Stack applicationStack application
Stack application
 
Polish
PolishPolish
Polish
 
Assignment6
Assignment6Assignment6
Assignment6
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
 

Ähnlich wie Infix to postfix

Ähnlich wie Infix to postfix (20)

Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
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
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
Lect-5 & 6.pptx
Lect-5 & 6.pptxLect-5 & 6.pptx
Lect-5 & 6.pptx
 
STACK Applications in DS
STACK Applications in DSSTACK Applications in DS
STACK Applications in DS
 
Lecture6
Lecture6Lecture6
Lecture6
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
CSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 02 Data & ExpressionsCSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 02 Data & Expressions
 
Stack Algorithm
Stack AlgorithmStack Algorithm
Stack Algorithm
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
 
stacks1
stacks1stacks1
stacks1
 
Team 4
Team 4Team 4
Team 4
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
Stack Applications
Stack ApplicationsStack Applications
Stack Applications
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 

Kürzlich hochgeladen

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 

Kürzlich hochgeladen (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 

Infix to postfix

  • 1. PRESENTATION OF DATA STRUCTURE & ALGORITHM BY Mohammad Saeed Farooqi
  • 2.  INFIX Notation.  POSTFIX Notation.  PREFIX Notation.  OPERATORS PRECEDENCE.  Evaluating Of POSTFIX Expression Using Stacks.  Converting INFIX To POSTFIX Using Stacks.  ALGORITHMS.  OUTLINES Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 3.  Infix Expression Are Those In Which Operators Are Written Between Two Operands.  Infix Expression Is The Common Arithmetic And Logical Formula Expression.  Infix Expression Needs Extra Information To Make The Order Of Evaluation Of The Operators Clear.  Rules Built Into The Language About Operator Precedence And Associativity, And Brackets ( ) To Allow Users To Override These Rules.  INFIX EXPRESSION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 4.  EXAMPLE…  A * ( B + C ) / D…  This Expression Is Usually Taken To Mean Something Like: "First Add B And C Together, Then Multiply The Result By A, Then Divide By D To Give The Final Answer.  INFIX EXPRESSION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 5.  POSTFIX Expression Also Known As “Reverse Polish Expression”  In These Expressions Operators Are Written After Their Operands.  Operators Act On Values Immediately To The Left Of Them.  They Do Not Have (Brackets)  POSTFIX EXPRESSION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 6.  EXAMPLE…  A B C + * D /…  Operators Act On Values Immediately To The Left Of Them.  For Example, The "+" Above Uses The "B" And "C".  We Can Add (Totally Unnecessary) Brackets To Make This Easy. ( (A (B C +) *) D /) .  POSTFIX EXPRESSION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 7.  Also Known As “Polish Expression”.  In These Expressions Operators Are Written Before The Operands.  We Have To Scan It From Right-To-Left.  As For Postfix, Operators Are Evaluated Left-To-Right And Brackets Are Superfluous.  Operators Act On The Two Nearest Values On The Right.  I Have Again Added (Totally Unnecessary) Brackets To Make This Clear. (/ (* A (+ B C) ) D)  PREFIX Notation Is Especially Popular With StackBased Operations Due To Its Innate Ability To Easily Distinguish Order Of Operations Without The Need For Parentheses.  PREFIX EXPRESSION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 8.  We Assume The Following Three Levels Of PRECEDENCE For The Usual Five Binary Operations.  Highest Exponentiation ().  Next Highest Multiplication (*) And Division (/) Superfluous  Lowest Addition (+) And Subtraction (-)  Without Understanding Operator Precedence You Can Not Convert Any Expression.  OPERATOR PRECEDENCE Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 9.  EVOLUACTION OF POSTFIX EXPRESSION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 10. • EvaluatePostfix(exp) • { • Create A Stack S. • for I ← 0 to length of the (exp)-1 { if(exp[i]) // Is An Operand push(exp[i]); else if(exp[i]) // Is An Operator { op1←pop(); op2← pop(); result←perform(exp[i],op1,op2); push(result); } } }  ALGORITHM FOR POSTFIX EVALUATION Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 11. Converting Infix To Postfix Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 12. • • • • • • • Example: 1*2+3. Scan: *,+ (Stack) And 12 (Postfix Expression). Precedence Of * Is Higher Than +. Thus, Append * to postfix Expression. + (Stack) And 12* (Postfix Expression ). Scan Further, + (Stack ) and 12*3 (Postfix Expression) There Are No Further Operators, Thus, Postfix Is 12*3+ Converting Infix To Postfix Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 13. Converting Infix To Prefix Mohammad Saeed Farooqi (University Of Swat, Pakistan)
  • 14. • Step 1. Push “)” onto STACK, and add “(“ to end of the A. • Step 2. Scan A from right to left and repeat step 3 to 6 for each element of A until the STACK is empty. • Step 3. If an operand is encountered add it to B. • Step 4. If a right parenthesis is encountered push it onto STACK. • Step 5. If an operator is encountered then: a. Repeatedly pop from STACK and add to B each operator (on the top of STACK) which has same or higher precedence than the operator. b. Add operator to STACK. • Step 6. If left parenthesis is encontered then a. Repeatedly pop from the STACK and add to B (each operator on top of stack until a left parenthesis is encounterd) b. Remove the left parenthesis. • Step 7. Exit Converting Infix To Postfix Mohammad Saeed Farooqi (University Of Swat, Pakistan)