SlideShare a Scribd company logo
1 of 13
DATA STRUCTURES 
STACK APPLICATIONS 
By 
Shanthi.S 
Saradhaswathi.G 
Thangapriyaa.V.B 
Sriram.N 
Ramesh.R 
Poornachandran.R
Conversion And Evaluation 
of Expressions 
Group - 4
Conversion And Evaluation of Expressions 
• Stack 
A Stack is an ordered list in which all 
insertions and deletions are made at one end 
called Top.
Expressions 
Expression is a string of operands and operators. 
Operands are some numeric values and operators 
are of two types : 
 Unary operators such as ‘+’ and ‘-’. 
Binary operators such as ‘+’, ‘-’, ‘*’, ‘/’ and 
exponential.
Types of Expressions 
• Infix Expressions 
• Postfix Expressions 
• Prefix Expressions
Infix Expressions 
• Parenthesis can be used in these expressions. 
• Infix expressions are the most natural way of 
representing expressions. 
Infix expression = Operand1 operator Operand2 
Examples: 1) (a+b) 
2) (a+b)*(c-d) 
3) a+b/c)*(d+f)
Postfix Expression 
In postfix expression, there are no 
parenthesis used. All the corresponding operands 
come first and then operator can be placed. 
Postfix Expression = Operand1 operand2 operator 
Examples: 
1) ab+ 
2) ab+cd- 
3) ab+c/df+*
Prefix Expression 
In prefix expression, there are no 
parentheses used. All the corresponding operators 
come first and then the operands are arranged. 
Prefix Expression = Operator Operand1 Operand2 
Examples: 
1) +ab 
2) *+ab-cd 
3) */+abc+df
Conversion of Infix to Postfix Expressions: 
Eg.: ((a-b)*(a+b)) 
S.No Input 
Character 
Stack Postfix Expressions 
1. ( ( 
2. ( (( 
3. a (( a 
4. - ((- a 
5. b ((- ab 
6. ) ( ab- 
7. * (* ab- 
8. ( (*( ab- 
9. a (*( ab-a 
10. + (*(+ ab-a 
11. b (*(+ ab-ab 
12. ) (* ab-ab+ 
13. ) Empty ab-ab+* 
The postfix expression is ab-ab+*
Conversion of Postfix to Prefix: 
Eg.:ABCDE/*-F/G++ 
Prefix = Operator Operand1 Operand2 
Step1: ABCDE/*-F/G++ 
Step2: ABC(/DE)*-F/G++ 
Step3: AB(*C/DE)-F/G++ 
Step4: A(-B*C/DE)F/G++ 
Step5: A(/-B*C/DEF)G++ 
Step6: A(+/-B*C/DEFG)+ 
Step7: +A+/-B*C/DEFG 
+A+/-B*C/DEFG is the prefix expression.
Conversion of Postfix to Infix form: 
Eg.:ABC(DE/*-F/G++ 
Infix = Operand1 Operator Operand2 
Step1: ABCDE/*-F/G++ 
Step2: ABC/DE*-F/G++ 
Step3: AB(C*(D/E)-F/G++ 
Step4: A(-B(C*D/E)))F/G++ 
Step5: A(((B-(C(D/E)))/F)G++ 
Step6: A(((B-(C(D/E))/F+G)+ 
Step7: (A+(B-(C*(D/E)))/F)+G)) 
(A+(B-(C*(D/E)))/F)+G)) is the infix expression.
Evaluation of Expressions 
Algorithm: 
Add the right paranthesis. 
Scan the expressions from left to right of each 
element until the closed parenthesis is 
encountered. 
If operand is encountered, then Push to Stack. 
If operator is encountered, then next two 
elements from Stack is Poped. 
Evaluate the expression with the operator . 
E.g.(b*c). 
Set the result to the Top of the Stack. 
Exit.
Evaluation of Postfix expression 
p=abc*/d+ 
Assume a=50, b=10, c=7, d=0 
Steps Symbols Scanned Stack 
1. ( 
2. 50{a} (,50 
3. 10{b} (,50,10 
4. 7{c} (,50,10,7 
5. * (,50,70 
6. / (,1.4 
7. 2{d} (,1.4,2 
8. + (,3.4 
9. ) 3.4

More Related Content

What's hot (19)

C Operators
C OperatorsC Operators
C Operators
 
CSC Millionaire
CSC MillionaireCSC Millionaire
CSC Millionaire
 
Stack application
Stack applicationStack application
Stack application
 
[Question Paper] Introduction To C++ Programming (Revised Course) [April / 2015]
[Question Paper] Introduction To C++ Programming (Revised Course) [April / 2015][Question Paper] Introduction To C++ Programming (Revised Course) [April / 2015]
[Question Paper] Introduction To C++ Programming (Revised Course) [April / 2015]
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Assignment12
Assignment12Assignment12
Assignment12
 
Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
 
Assignment7
Assignment7Assignment7
Assignment7
 
Python Basic Operators
Python Basic OperatorsPython Basic Operators
Python Basic Operators
 
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
[Question Paper] Advanced SQL (Revised Course) [January / 2014][Question Paper] Advanced SQL (Revised Course) [January / 2014]
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
F# Eye 4 the C# Guy
F# Eye 4 the C# GuyF# Eye 4 the C# Guy
F# Eye 4 the C# Guy
 
Assignment10
Assignment10Assignment10
Assignment10
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
 
Operators
OperatorsOperators
Operators
 

Viewers also liked

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 stackHaqnawaz Ch
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
 
Infix postfixcoversion
Infix postfixcoversionInfix postfixcoversion
Infix postfixcoversionPdr Patnaik
 
Computer notes - Postfix
Computer notes  - PostfixComputer notes  - Postfix
Computer notes - Postfixecomputernotes
 
Evaluation of postfix expression
Evaluation of postfix expressionEvaluation of postfix expression
Evaluation of postfix expressionAkhil Ahuja
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examplesmua99
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversionSyed Mustafa
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 

Viewers also liked (18)

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
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
Stack
StackStack
Stack
 
Data structures
Data structuresData structures
Data structures
 
Stack
StackStack
Stack
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Stack
StackStack
Stack
 
Infix postfixcoversion
Infix postfixcoversionInfix postfixcoversion
Infix postfixcoversion
 
Computer notes - Postfix
Computer notes  - PostfixComputer notes  - Postfix
Computer notes - Postfix
 
Evaluation of postfix expression
Evaluation of postfix expressionEvaluation of postfix expression
Evaluation of postfix expression
 
12. Stack
12. Stack12. Stack
12. Stack
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversion
 
Infix to postfix
Infix to postfixInfix to postfix
Infix to postfix
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Stack
StackStack
Stack
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 

Similar to Team 4 (20)

Lec19
Lec19Lec19
Lec19
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.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
 
DS1.pptx
DS1.pptxDS1.pptx
DS1.pptx
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
Lecture6
Lecture6Lecture6
Lecture6
 
7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx7-Operator Precedence Parser-23-05-2023.pptx
7-Operator Precedence Parser-23-05-2023.pptx
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
EXPRESSIONS.pptx
EXPRESSIONS.pptxEXPRESSIONS.pptx
EXPRESSIONS.pptx
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Lect-5 & 6.pptx
Lect-5 & 6.pptxLect-5 & 6.pptx
Lect-5 & 6.pptx
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
 
Conversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad balochConversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad baloch
 
1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stack
StackStack
Stack
 
MO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.pptMO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.ppt
 

More from Sathasivam Rangasamy (11)

deque and it applications
deque and it applicationsdeque and it applications
deque and it applications
 
Team 2
Team 2Team 2
Team 2
 
Team 1
Team 1Team 1
Team 1
 
Team 10
Team 10Team 10
Team 10
 
Team 9
Team 9Team 9
Team 9
 
linkedlist
linkedlistlinkedlist
linkedlist
 
single linked list
single linked listsingle linked list
single linked list
 
Team 6
Team 6Team 6
Team 6
 
Team 5
Team 5Team 5
Team 5
 
Team 3
Team 3Team 3
Team 3
 
Loaders
LoadersLoaders
Loaders
 

Team 4

  • 1. DATA STRUCTURES STACK APPLICATIONS By Shanthi.S Saradhaswathi.G Thangapriyaa.V.B Sriram.N Ramesh.R Poornachandran.R
  • 2. Conversion And Evaluation of Expressions Group - 4
  • 3. Conversion And Evaluation of Expressions • Stack A Stack is an ordered list in which all insertions and deletions are made at one end called Top.
  • 4. Expressions Expression is a string of operands and operators. Operands are some numeric values and operators are of two types :  Unary operators such as ‘+’ and ‘-’. Binary operators such as ‘+’, ‘-’, ‘*’, ‘/’ and exponential.
  • 5. Types of Expressions • Infix Expressions • Postfix Expressions • Prefix Expressions
  • 6. Infix Expressions • Parenthesis can be used in these expressions. • Infix expressions are the most natural way of representing expressions. Infix expression = Operand1 operator Operand2 Examples: 1) (a+b) 2) (a+b)*(c-d) 3) a+b/c)*(d+f)
  • 7. Postfix Expression In postfix expression, there are no parenthesis used. All the corresponding operands come first and then operator can be placed. Postfix Expression = Operand1 operand2 operator Examples: 1) ab+ 2) ab+cd- 3) ab+c/df+*
  • 8. Prefix Expression In prefix expression, there are no parentheses used. All the corresponding operators come first and then the operands are arranged. Prefix Expression = Operator Operand1 Operand2 Examples: 1) +ab 2) *+ab-cd 3) */+abc+df
  • 9. Conversion of Infix to Postfix Expressions: Eg.: ((a-b)*(a+b)) S.No Input Character Stack Postfix Expressions 1. ( ( 2. ( (( 3. a (( a 4. - ((- a 5. b ((- ab 6. ) ( ab- 7. * (* ab- 8. ( (*( ab- 9. a (*( ab-a 10. + (*(+ ab-a 11. b (*(+ ab-ab 12. ) (* ab-ab+ 13. ) Empty ab-ab+* The postfix expression is ab-ab+*
  • 10. Conversion of Postfix to Prefix: Eg.:ABCDE/*-F/G++ Prefix = Operator Operand1 Operand2 Step1: ABCDE/*-F/G++ Step2: ABC(/DE)*-F/G++ Step3: AB(*C/DE)-F/G++ Step4: A(-B*C/DE)F/G++ Step5: A(/-B*C/DEF)G++ Step6: A(+/-B*C/DEFG)+ Step7: +A+/-B*C/DEFG +A+/-B*C/DEFG is the prefix expression.
  • 11. Conversion of Postfix to Infix form: Eg.:ABC(DE/*-F/G++ Infix = Operand1 Operator Operand2 Step1: ABCDE/*-F/G++ Step2: ABC/DE*-F/G++ Step3: AB(C*(D/E)-F/G++ Step4: A(-B(C*D/E)))F/G++ Step5: A(((B-(C(D/E)))/F)G++ Step6: A(((B-(C(D/E))/F+G)+ Step7: (A+(B-(C*(D/E)))/F)+G)) (A+(B-(C*(D/E)))/F)+G)) is the infix expression.
  • 12. Evaluation of Expressions Algorithm: Add the right paranthesis. Scan the expressions from left to right of each element until the closed parenthesis is encountered. If operand is encountered, then Push to Stack. If operator is encountered, then next two elements from Stack is Poped. Evaluate the expression with the operator . E.g.(b*c). Set the result to the Top of the Stack. Exit.
  • 13. Evaluation of Postfix expression p=abc*/d+ Assume a=50, b=10, c=7, d=0 Steps Symbols Scanned Stack 1. ( 2. 50{a} (,50 3. 10{b} (,50,10 4. 7{c} (,50,10,7 5. * (,50,70 6. / (,1.4 7. 2{d} (,1.4,2 8. + (,3.4 9. ) 3.4