SlideShare uma empresa Scribd logo
1 de 16
A
Data Structure
   What is a Stack

   Stack Operations

   LIFO Stack

   Animation Depicting Push Operation

   Animation Depicting Pop Operation

   Array Implementation of Stack

   Applications of stack
        Checking for balanced braces
        Converting Infix Expression to Postfix
        Postfix calculator
What is a Stack?
A  stack is a Last In, First Out (LIFO) data
structure,objects inserted last are the first to
come out of the stack


Anything  added to the stack goes on the “top”
of the stack


Anything  removed from the stack is taken from
the “top” of the stack


Things  are removed in the reverse order from
that in which they were inserted
Stack Operations
   PUSH
     Adds the object to the top of the stack

   POP
     Removes the object at the top of the stack
      and returns it

   PEEK
      Returns the top object of the stack but does
      not remove it from the stack

   ISEMPTY
      Returns True if Stack is empty
A LIFO Stack
                Push            Pop




Stack Pointer           Top




                       Bottom
array Implementation of Stack
                         A[1] A[2] ….         ….    ….    A[n]


Push X                    w   y       x



            Stack pointer         Stack pointer       After many   Stack pointer
                 J=2                   J=3            Push Ops          J=n
             Before Push           After Push                        Stack Full




Pop                       w   y

After many Pop ops

         Stack Pointer        Stack Pointer        Stack Pointer
             J=0                   J=2                 J=3
         Stack Empty            After Pop           Before Pop
Checking for Balanced Braces

   ([]({()}[()])) is balanced; ([]({()}[())]) is not
   Simple counting is not enough to check
    balance
   You can do it with a stack: going left to
    right,
      If you see a (, [, or {, push it on the
        stack
      If you see a ), ], or }, pop the stack
        and check whether you got the
        corresponding (, [, or {
      When you reach the end, check that the
        stack is empty
Converting Infix Expressions to Equivalent
               Postfix Expressions
   Infix Expression         a+b

   Postfix Expression       ab+

   An infix expression can be evaluated by first
    being converted into an equivalent postfix
    expression

   Facts about converting from infix to postfix
     Operands always stay in the same order with
      respect to one another
     All parentheses are removed
Algorithm : Converting Infix Expression to
               Postfix using stack

  Suppose X is an arithmetic expression written in infix notation.
  This algorithm finds the equivalent postfix expression Y.

   1. Push "(" onto STACK, and add ")" to the end of X.
   2. Scan X from left to right and REPEAT Steps 3 to 6 for each element of X UNTIL the
       STACK is empty :
   3. If an operand is encountered, add it to Y.
   4. If a left parenthesis is encountered, push it onto STACK.
   5. If an operator is encountered, then :
   (a) Repeatedly pop from STACK and add to Y each operator (on the top of STACK) which has
   the same precedence as or higher precedence than operator.
   (b) Add operator to STACK.
   /* End of If structure * /
   6. If a right parenthesis is encountered, then :
   (a) Repeatedly pop from STACK and add to Y each operator (on the top of STACK)
   until a left parenthesis is encountered.
   (b) Remove the left parenthesis. [Do not add the left parenthesis to Y].
   /* End of If structure * /
   /* End of Step 2 loop * /
   7. END.
A trace of the algorithm that converts the infix expression
             a - (b + c * d)/e to postfix form
A postfix calculator
   When an operand is entered, the calculator
     Pushes it onto a stack



   When an operator is entered, the calculator
     Applies it to the top (one or two, depending
      on unary or binary operator) operand(s) of
      the stack

       Pops the operands from the stack

       Pushes the result of the operation on the
        stack
The action of a postfix calculator when evaluating the expression 2 * (3 + 4)
                        Postfix Notation--- 2 3 4 + *
Acknowledgement

   Data Structures BY Tanenbaum
   Internet
   Computer Science C++ A textbook for class XII        -By
    Sumita Arora




                         prepared by-
                            Seema kaushik,
                    Computer science department,
                 DAV public school, sector-14, gurgaon

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Queues
QueuesQueues
Queues
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Linked list
Linked listLinked list
Linked list
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 

Destaque

Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 
Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Permutation & Combination
Permutation & CombinationPermutation & Combination
Permutation & CombinationPuru Agrawal
 
Permutations and combinations examples
Permutations and combinations examplesPermutations and combinations examples
Permutations and combinations examplesLeo Crisologo
 
Permutation and combination
Permutation and combinationPermutation and combination
Permutation and combinationSadia Zareen
 
Permutations & Combinations
Permutations & CombinationsPermutations & Combinations
Permutations & Combinationsrfant
 

Destaque (7)

16 combinatroics-2
16 combinatroics-216 combinatroics-2
16 combinatroics-2
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Permutation & Combination
Permutation & CombinationPermutation & Combination
Permutation & Combination
 
Permutations and combinations examples
Permutations and combinations examplesPermutations and combinations examples
Permutations and combinations examples
 
Permutation and combination
Permutation and combinationPermutation and combination
Permutation and combination
 
Permutations & Combinations
Permutations & CombinationsPermutations & Combinations
Permutations & Combinations
 

Semelhante a Stack

stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfKalpana Mohan
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxchandankumar364348
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversionRashmiranja625
 
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Ramachandra Adiga G
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxhaaamin01
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
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 .pdfarihantsherwani
 
STACK USING LISTS.pptx
STACK USING LISTS.pptxSTACK USING LISTS.pptx
STACK USING LISTS.pptxBaby81727
 

Semelhante a Stack (20)

stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdf
 
stack-Intro.pptx
stack-Intro.pptxstack-Intro.pptx
stack-Intro.pptx
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
CH4.pptx
CH4.pptxCH4.pptx
CH4.pptx
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Data structures
Data structures Data structures
Data structures
 
Stacks
StacksStacks
Stacks
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
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
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
STACK USING LISTS.pptx
STACK USING LISTS.pptxSTACK USING LISTS.pptx
STACK USING LISTS.pptx
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 
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
 

Último

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Stack

  • 2. What is a Stack  Stack Operations  LIFO Stack  Animation Depicting Push Operation  Animation Depicting Pop Operation  Array Implementation of Stack  Applications of stack Checking for balanced braces Converting Infix Expression to Postfix Postfix calculator
  • 3. What is a Stack? A stack is a Last In, First Out (LIFO) data structure,objects inserted last are the first to come out of the stack Anything added to the stack goes on the “top” of the stack Anything removed from the stack is taken from the “top” of the stack Things are removed in the reverse order from that in which they were inserted
  • 4. Stack Operations  PUSH Adds the object to the top of the stack  POP Removes the object at the top of the stack and returns it  PEEK Returns the top object of the stack but does not remove it from the stack  ISEMPTY Returns True if Stack is empty
  • 5. A LIFO Stack Push Pop Stack Pointer Top Bottom
  • 6.
  • 7.
  • 8. array Implementation of Stack A[1] A[2] …. …. …. A[n] Push X w y x Stack pointer Stack pointer After many Stack pointer J=2 J=3 Push Ops J=n Before Push After Push Stack Full Pop w y After many Pop ops Stack Pointer Stack Pointer Stack Pointer J=0 J=2 J=3 Stack Empty After Pop Before Pop
  • 9. Checking for Balanced Braces  ([]({()}[()])) is balanced; ([]({()}[())]) is not  Simple counting is not enough to check balance  You can do it with a stack: going left to right,  If you see a (, [, or {, push it on the stack  If you see a ), ], or }, pop the stack and check whether you got the corresponding (, [, or {  When you reach the end, check that the stack is empty
  • 10.
  • 11. Converting Infix Expressions to Equivalent Postfix Expressions  Infix Expression a+b  Postfix Expression ab+  An infix expression can be evaluated by first being converted into an equivalent postfix expression  Facts about converting from infix to postfix  Operands always stay in the same order with respect to one another  All parentheses are removed
  • 12. Algorithm : Converting Infix Expression to Postfix using stack Suppose X is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression Y. 1. Push "(" onto STACK, and add ")" to the end of X. 2. Scan X from left to right and REPEAT Steps 3 to 6 for each element of X UNTIL the STACK is empty : 3. If an operand is encountered, add it to Y. 4. If a left parenthesis is encountered, push it onto STACK. 5. If an operator is encountered, then : (a) Repeatedly pop from STACK and add to Y each operator (on the top of STACK) which has the same precedence as or higher precedence than operator. (b) Add operator to STACK. /* End of If structure * / 6. If a right parenthesis is encountered, then : (a) Repeatedly pop from STACK and add to Y each operator (on the top of STACK) until a left parenthesis is encountered. (b) Remove the left parenthesis. [Do not add the left parenthesis to Y]. /* End of If structure * / /* End of Step 2 loop * / 7. END.
  • 13. A trace of the algorithm that converts the infix expression a - (b + c * d)/e to postfix form
  • 14. A postfix calculator  When an operand is entered, the calculator  Pushes it onto a stack  When an operator is entered, the calculator  Applies it to the top (one or two, depending on unary or binary operator) operand(s) of the stack  Pops the operands from the stack  Pushes the result of the operation on the stack
  • 15. The action of a postfix calculator when evaluating the expression 2 * (3 + 4) Postfix Notation--- 2 3 4 + *
  • 16. Acknowledgement  Data Structures BY Tanenbaum  Internet  Computer Science C++ A textbook for class XII -By Sumita Arora prepared by- Seema kaushik, Computer science department, DAV public school, sector-14, gurgaon