
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
It is all about stacks in data structure. You can use it as reference to your study.
Typology: Study notes
1 / 40
This page cannot be seen from the preview
Don't miss anything!

































The Stack
3.4. APPLICATIONS OF STACKS There are a number of applications of stacks: ๏ฑ Stack is internally used by compiler when we implement (or execute) any recursive function. ๏ฑ Stack is also used to evaluate a mathematical expression and to check the parentheses in an expression.
The Stack
The Stack
The Stack
The Stack
Recursion of course is an elegant programming technique, but not the best way to solve a problem, even if it is recursive in nature. This is due to the following reasons:
The Stack
3.4.3. EXPRESSION Another application of stack is calculation of postfix expression. There are basically three types of notation for an expression (mathematical expression; An expression is defined as the number of operands or data items combined with several operators .)
**1. Infix notation
The infix notation is what we come across in our general mathematics, where the operator is written in-between the operands. For example : A + B In the prefix notation the operator(s) are written before the operands, like: + A B In the postfix notation the operator(s) are written after the operands, like: A B +
The Stack
The Stack
Human beings are quite used to work with mathematical expressions in infix notation , which is rather complex. Whenever an infix expression consists of more than one operator, the precedence rules ( BODMAS ) should be applied to decide which operator (and operand) is evaluated first. But in a postfix expression operands appear before the operator , so there is no need for operator precedence and other rules.
The Stack
C++ Operator Precedence
The Stack Algorithm
The Stack
I =(A+(BC-(D/E^F)G)H) Sr. No Symbol Scanned STACK Postfix_Stack (Q) 1 A ( A 2 + (+ A 3 ( (+( A 4 B (+( AB 5 * (+( AB 6 C (+(* ABC 7 - (+(- ABC* 8 ( (+(-( ABCD 9 D (+(-( ABCD**
The Stack
The rules to be remembered during infix to postfix conversion are:
The Stack
A B C * + D E / F * -