Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
8 views
7 pages
Into Post
Stack infix postfix
Uploaded by
samarjeet.galaxy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Into Post For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
8 views
7 pages
Into Post
Stack infix postfix
Uploaded by
samarjeet.galaxy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Into Post For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 7
Search
Fullscreen
How to convert an Infix expression to a Postfix expression? To convert infix expression to postfix expression, use the stack data structure. Scan the infix expression from left to right. Whenever we get an operand, add it to the postfix expression and if we get an operator or parenthesis add it to the stack by maintaining their precedence. Below are the steps to implement the above idea: 1. Scan the infix expression from left to right. 2. If the scanned character is an operand, put it in the postfix expression. 3. Otherwise, do the following + If the precedence and associativity of the scanned operator are greater than the precedence and associativity of the operator in the stack [or the stack is empty or the stack contains a ‘(' J, then push it in the stack. ['’ operator is right associative and other operators like ‘+'/—',*' and ‘/' are left-associative]. © Check especially for a condition when the operator at the top of the stack and the scanned operator both are ‘*". In this condition, the precedence of the scanned operator is higher due to its right associativity. So it will be pushed into the operator stack. © Inall the other cases when the top of the operator stack is the same as. the scanned operator, then pop the operator from the stack because of left associativity due to which the scanned operator has less precedence. + Else, Pop all the operators from the stack which are greater than or equal to in precedence than that of the scanned operator. © After doing that Push the scanned operator to the stack. (If you encounter parenthesis while popping then stop there and push the scanned operator in the stack.) 4. If the scanned character is a ‘(', push it to the stack. 5. If the scanned character is a)’, pop the stack and output it until a ‘(’ is encountered, and discard both the parenthesis. 6. Repeat steps 2-5 until the infix expression is scanned.7. Once the scanning is over, Pop the stack and add the operators in the postfix expression until it is not empty. 8. Finally, print the postfix expression. Illustration: Follow the below illustration for a better understanding Consider the infix expression exp = “a+b*c+d” and the infix expression is scanned using the iterator i, which is initialized as i = 0. 1st Step: Here i = 0 and expli = ‘a’ i.e., an operand. So add this in the posttix expression. Therefore, postfix = “a” Pe ete Add ‘ain the postfix 2nd Step: Here i = 1 and exp[i] = ‘+’ i.e., an operator. Push this into the stack. postfix = “a” and stack = {4}.Add ‘+' into stack feiss Push ‘+"in the stack 3rd Step: Now i = 2 and expfi] = ‘b’ ie., an operand. So add this in the postfix expression. postfix = “ab” and stack = {+}. postfix = "ab" PPI aul ence Add ‘bin the postfix 4th Step: Now i = 3 and exp[i] = *’ie., an operator. Push this into the stack. postfix = “ab” and stack = {+, *}.Add ™ into stack Postfix = "ab" * has higher precedence. Push it into stack Push "in the stack 5th Step: Now i= 4 and expfi] = ‘c’.e., an operand. Add this in the postfix expression. postfix = “abe” and stack = {+, *} Pie ete ‘Add ‘c'in the postfix 6th Step: Now i= 5 and exp[i] = ‘+’ i.e., an operator. The topmost element of the stack has higher precedence. So pop until the stack becomes empty or the top element has less precedence. *’ is popped and added in postfix. So postfix = “abc*” and stack = {+}.Add to postfix Pre ed ecko uky Pop and add in postibe Now top element is ‘+' that also doesn't have less precedence. Pop it. postfix = “abot”. Add to postfix eee cae Pop ‘*" and add it in postfix Now stack is empty. So push ‘+’ in the stack. stack = {+}.Add ‘+' into stack postfix = "abc*+" feiss Push ‘+"in the stack 7th Step: Now i = 6 and exp[i] = ‘d’i.e., an operand. Add this in the postfix expression. postfix = “abe*+d”. EUPruR Macnee Add ‘an the postfix Final Step: Now no element is left. So empty the stack and add it in the postfix expression. postfix = “abc*+d+".Add to postfix “abc*+d+" Bee Pop '+" and add itn postfix
You might also like
Lab Manual 6 Implemenation of A Program To Convert A Given Infix Expression To Postfix Form Using Stacks
PDF
No ratings yet
Lab Manual 6 Implemenation of A Program To Convert A Given Infix Expression To Postfix Form Using Stacks
3 pages
Stacks
PDF
No ratings yet
Stacks
16 pages
Applications of Stack
PDF
No ratings yet
Applications of Stack
7 pages
Lec Stack
PDF
No ratings yet
Lec Stack
28 pages
Unit 4 L2.1 infixToPostfixConversionV2
PDF
No ratings yet
Unit 4 L2.1 infixToPostfixConversionV2
33 pages
Infix To Postfix Expression Algorithm and Example (2022)
PDF
100% (1)
Infix To Postfix Expression Algorithm and Example (2022)
3 pages
File 1692869285 110340 Stackinfix Post Pre Exp
PDF
No ratings yet
File 1692869285 110340 Stackinfix Post Pre Exp
59 pages
Worksheet1 HL
PDF
No ratings yet
Worksheet1 HL
2 pages
Prog 4
PDF
No ratings yet
Prog 4
5 pages
CS DataStructure-Lecture 6 - Polish Notation
PDF
No ratings yet
CS DataStructure-Lecture 6 - Polish Notation
35 pages
DS Lecture 04. 2 Queue APP
PDF
No ratings yet
DS Lecture 04. 2 Queue APP
17 pages
Unit 2a Stacks
PDF
No ratings yet
Unit 2a Stacks
15 pages
CC213 Lec06
PDF
No ratings yet
CC213 Lec06
50 pages
CH4 Stack and Queue Last Edited
PDF
No ratings yet
CH4 Stack and Queue Last Edited
61 pages
Stack Application 1
PDF
No ratings yet
Stack Application 1
7 pages
Ds-Unit-2-Expressions Conversion
PDF
No ratings yet
Ds-Unit-2-Expressions Conversion
18 pages
Rules For Converting An Infix Expression To A Prefix Expression and Codes
PDF
No ratings yet
Rules For Converting An Infix Expression To A Prefix Expression and Codes
17 pages
EXP 2 - DS - Ujjay - 33
PDF
No ratings yet
EXP 2 - DS - Ujjay - 33
7 pages
CS301 Lec07
PDF
No ratings yet
CS301 Lec07
36 pages
Unit 2 Stack
PDF
No ratings yet
Unit 2 Stack
7 pages
Infix, Prefix, Postfix
PDF
100% (2)
Infix, Prefix, Postfix
57 pages
WINSEM2018-19 - CSE2003 - ETH - SJT311 - VL2018195002472 - Reference Material I - Infix To Postfix AND Postfix Evaluation
PDF
No ratings yet
WINSEM2018-19 - CSE2003 - ETH - SJT311 - VL2018195002472 - Reference Material I - Infix To Postfix AND Postfix Evaluation
24 pages
Stack Apllication in DS
PDF
No ratings yet
Stack Apllication in DS
13 pages
Infix Postfix
PDF
No ratings yet
Infix Postfix
27 pages
Infix Post Pre
PDF
No ratings yet
Infix Post Pre
6 pages
CHAPTER 4 STACKS New
PDF
No ratings yet
CHAPTER 4 STACKS New
55 pages
Lecture 04.2
PDF
No ratings yet
Lecture 04.2
17 pages
Polish Notation
PDF
No ratings yet
Polish Notation
10 pages
Stack Application of in Expression Evaluation
PDF
No ratings yet
Stack Application of in Expression Evaluation
7 pages
DSSlides M2
PDF
No ratings yet
DSSlides M2
73 pages
Stack Assignment
PDF
No ratings yet
Stack Assignment
4 pages
Stack ADT-Operations
PDF
No ratings yet
Stack ADT-Operations
17 pages
6 Dsa
PDF
No ratings yet
6 Dsa
130 pages
DSA Unit 2 Stack
PDF
No ratings yet
DSA Unit 2 Stack
37 pages
Infix Expression To Postfix Expression
PDF
No ratings yet
Infix Expression To Postfix Expression
10 pages
Prefix Infix Postfix
PDF
No ratings yet
Prefix Infix Postfix
2 pages
2 - Infixtopostfix
PDF
No ratings yet
2 - Infixtopostfix
7 pages
Stack Application
PDF
No ratings yet
Stack Application
4 pages
2 1stack
PDF
No ratings yet
2 1stack
66 pages
Exp 4
PDF
No ratings yet
Exp 4
6 pages
Lecture 04.2
PDF
No ratings yet
Lecture 04.2
17 pages
The Polish Notation (Application of Stacks)
PDF
No ratings yet
The Polish Notation (Application of Stacks)
23 pages
INFIXTOPOSTFIX
PDF
No ratings yet
INFIXTOPOSTFIX
45 pages
Lec 3 Expresions
PDF
No ratings yet
Lec 3 Expresions
23 pages
Stack & Queue Applications: Dept. of Computer Science Faculty of Science and Technology
PDF
No ratings yet
Stack & Queue Applications: Dept. of Computer Science Faculty of Science and Technology
18 pages
DS Week 8 Lecture Rev Operations of Stacks Part 2 by DR Gaurav
PDF
No ratings yet
DS Week 8 Lecture Rev Operations of Stacks Part 2 by DR Gaurav
34 pages
Dsu T
PDF
No ratings yet
Dsu T
13 pages
Application of Stack
PDF
No ratings yet
Application of Stack
26 pages
Infixprefixpostfix
PDF
No ratings yet
Infixprefixpostfix
7 pages
Lecture 05
PDF
No ratings yet
Lecture 05
49 pages
5 Stack 29 05 2024
PDF
No ratings yet
5 Stack 29 05 2024
33 pages
10.polish Expressions Unit-2
PDF
No ratings yet
10.polish Expressions Unit-2
16 pages
Lecture 2.1.4 Application of Stacks
PDF
No ratings yet
Lecture 2.1.4 Application of Stacks
54 pages
Application of Stacks
PDF
No ratings yet
Application of Stacks
49 pages
Expression Conversion With Stack
PDF
No ratings yet
Expression Conversion With Stack
44 pages
Lec 8 - Polish Notation 24102022 101228am
PDF
No ratings yet
Lec 8 - Polish Notation 24102022 101228am
17 pages
EEE 212 - Algorithms & Data Structures: Applications of Stacks (Continued)
PDF
No ratings yet
EEE 212 - Algorithms & Data Structures: Applications of Stacks (Continued)
2 pages
Lecture 12 Polish Notation PDF
PDF
No ratings yet
Lecture 12 Polish Notation PDF
36 pages
Data Structure
PDF
No ratings yet
Data Structure
7 pages