SlideShare a Scribd company logo
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

PPT
Expression evaluation
PPTX
Unit I - Evaluation of expression
PPT
Application of Stacks
PDF
Assignment6
PPTX
stack
PPTX
Increment and Decrement operators in C++
PPT
Conversion of Infix To Postfix Expressions
Expression evaluation
Unit I - Evaluation of expression
Application of Stacks
Assignment6
stack
Increment and Decrement operators in C++
Conversion of Infix To Postfix Expressions

What's hot (19)

PPT
CSC Millionaire
PPT
Stack application
PDF
[Question Paper] Introduction To C++ Programming (Revised Course) [April / 2015]
PPSX
Stacks Implementation and Examples
PDF
Applications of stack
PDF
Assignment12
PPT
Stack Data Structure V1.0
PDF
Assignment7
PDF
Python Basic Operators
PDF
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
PPTX
Stack data structure
PPT
Data structure lecture7
PPTX
Unit 3 stack
PPTX
F# Eye 4 the C# Guy
PDF
Assignment10
PDF
Applications of stack
PPT
Functional techniques in Ruby
PPT
Operators
CSC Millionaire
Stack application
[Question Paper] Introduction To C++ Programming (Revised Course) [April / 2015]
Stacks Implementation and Examples
Applications of stack
Assignment12
Stack Data Structure V1.0
Assignment7
Python Basic Operators
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
Stack data structure
Data structure lecture7
Unit 3 stack
F# Eye 4 the C# Guy
Assignment10
Applications of stack
Functional techniques in Ruby
Operators
Ad

Viewers also liked (18)

DOCX
Conversion from infix to prefix using stack
PPT
01 stack 20160908_jintaek_seo
PPT
PPTX
Data structures
PPSX
Data Structure (Stack)
PDF
PPTX
Infix postfixcoversion
PPT
Computer notes - Postfix
PPTX
Evaluation of postfix expression
PPT
12. Stack
DOC
Infix to-postfix examples
PDF
Infix prefix postfix expression -conversion
PPTX
Infix to postfix
PPTX
Infix to postfix conversion
PPT
Stack Data Structure & It's Application
PPSX
PPTX
STACKS IN DATASTRUCTURE
Conversion from infix to prefix using stack
01 stack 20160908_jintaek_seo
Data structures
Data Structure (Stack)
Infix postfixcoversion
Computer notes - Postfix
Evaluation of postfix expression
12. Stack
Infix to-postfix examples
Infix prefix postfix expression -conversion
Infix to postfix
Infix to postfix conversion
Stack Data Structure & It's Application
STACKS IN DATASTRUCTURE
Ad

Similar to Team 4 (20)

PPTX
week9-prefixinfixandpostfixnotations-191013065821.pptx
PPT
PPTX
Prefix, Infix and Post-fix Notations
PPTX
Topic 2_revised.pptx
PPTX
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
PDF
Data Structures And Algorithms(stacks queues)
PPTX
Stack application in infix to prefix expression
PPTX
data structure stack appplication in python
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
PPTX
Prefix and PostFIx presentation for DSA .pptx
PPTX
Stack Data Structure Intro and Explanation
PPTX
Data strutcure and annalysis topic stack
PPTX
DS1.pptx
PPTX
Data structures (Infix, Prefix and Postfix notations).pptx
PPTX
data structure notes for engi DSA1 (2).pptx
PPTX
Lecture_04.2.pptx
PPTX
Precedence of operators IN C PROGRAMMING
PPTX
Basic operators and it's types in c languages
PDF
Data structure and algorithm.(dsa)
PPT
Lecture6
week9-prefixinfixandpostfixnotations-191013065821.pptx
Prefix, Infix and Post-fix Notations
Topic 2_revised.pptx
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
Data Structures And Algorithms(stacks queues)
Stack application in infix to prefix expression
data structure stack appplication in python
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
Prefix and PostFIx presentation for DSA .pptx
Stack Data Structure Intro and Explanation
Data strutcure and annalysis topic stack
DS1.pptx
Data structures (Infix, Prefix and Postfix notations).pptx
data structure notes for engi DSA1 (2).pptx
Lecture_04.2.pptx
Precedence of operators IN C PROGRAMMING
Basic operators and it's types in c languages
Data structure and algorithm.(dsa)
Lecture6

More from Sathasivam Rangasamy (11)

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