SlideShare a Scribd company logo
1 of 10
Download to read offline
S
                      T
                      A
                      C
www.eshikshak.co.in   K
INTRODUCTION

● Array allows to insert and delete an element at any place in the list

● STACK is a list of elements

● It is a linear data structure

● Insertion and deletion operation is performed only at one end –
  known as top of stack

● Also known as Last-in-First-out (LIFO), entries are removed in
  reverse order of insertion



                        www.eshikshak.co.in
BASIC OPERATIONS OF STACKS

● push -- insert item on stack

● pop -- remove item from stack

● peek -- examine, but don’t remove item

● isEmpty – reports whether or not stack is empty

● isFull- reports whether or not stack is full

● size – returns # of items in stack



                        www.eshikshak.co.in
PUSH OPERATION

   ● Inserting element in a stack is known as PUSH
   ● When elements are inserted continuously to the stack it grows at one
     end i.e. top


                                                               Top    9
                                                               =>
                                                  Top     6           8
                                                  =>
                                     Top     -7          -7           -7
                                     =>
                       Top     8             8            8           8
                       =>
           Top     5           5             5            5           5
           =>
Top =
NULL
                         www.eshikshak.co.in
POP OPERATION

  ● Removing of element from a stack is known as pop
  ● When elements are removed continuously from a stack, it shrinks at
    the same end i.e. top


Top    9
=>
       8   Top     6
           =>
      -7           -7    Top    -7
                         =>
       8           8             8   Top     8
                                     =>
       5           5             5           5    Top    5
                                                  =>
                                                             Top =
                                                             NULL
                        www.eshikshak.co.in
STACKS CONDITIONS

● Depending on implementation,
                                        ● Important to know if stack is
  may be necessary to check if
                                          empty -- attempt to remove an
  stack is full -- attempt to add
                                          item from an empty stack is an
  item to a full stack is an overflow
                                          underflow error.
  error


        Top     9
        =>
                8

                -7

                8

                5
                                                Top =
                                                NULL
                          www.eshikshak.co.in
PUSH(STACK, TOP, MAXSTK, ITEM)

STACK - Linear Array, TOP – location of top element in stack,
MAXSTK – Numbers of elements that be stored in Stack,
ITEM – value that has to be inserted in stack

 STEP 1. if top = MaxStk, then
 print “Overflow” and return

 STEP 2. set top=top + 1

 STEP 3. set STACK[top] = item

 STEP 4. Return



                           www.eshikshak.co.in
PUSH(STACK, TOP)

STACK - Linear Array, TOP – location of top element in stack,
ITEM – value that has to be inserted in stack

 1. [check for underflow of the stack]
 if TOP=-1 then
 Write(“stack underflow on pop)
 end if
 2. [ Assign the top element of the stack to ITEM]
      ITEM = STACK[TOP]
 2. [decrement pointer]
 TOP=TOP-1
 3. [return former top element of the stack]
 Return(ITEM)
 4. Exit
                           www.eshikshak.co.in
PEEP(STACK,TOP)

1. [check for stack underflow]
if TOP-I+1<=0 then
Write (“stack underflow on peep”)
end if
2. [Return the top element of the stack]
Return(stack[TOP-MAX+1])
3. Exit




                       www.eshikshak.co.in
APPLICATIONS OF STACK

● Undo
● Redo
● Function Call
● Recursive Function Call
● Convert infix to Postfix expression
● Convert infix to Prefix expression
● Evaluate infix expression
● Tower of hanoi
● Reverse string or list or file




                       www.eshikshak.co.in

More Related Content

Viewers also liked

Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Jay Patel
 
Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Jay Patel
 
Web01 091024130908-phpapp01
Web01 091024130908-phpapp01Web01 091024130908-phpapp01
Web01 091024130908-phpapp01Jay Patel
 
Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Jay Patel
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)Jay Patel
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)Jay Patel
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermediaJay Patel
 
Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Jay Patel
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)Jay Patel
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring toolsJay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 

Viewers also liked (13)

Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01
 
Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01
 
Web01 091024130908-phpapp01
Web01 091024130908-phpapp01Web01 091024130908-phpapp01
Web01 091024130908-phpapp01
 
Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermedia
 
Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring tools
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 

Similar to Stack Operations and Applications

Similar to Stack Operations and Applications (20)

Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Stack
StackStack
Stack
 
Chapter 5-stack.pptx
Chapter 5-stack.pptxChapter 5-stack.pptx
Chapter 5-stack.pptx
 
Stacks
StacksStacks
Stacks
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
04 stacks
04 stacks04 stacks
04 stacks
 
Stack
StackStack
Stack
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
chapter8-stack-161018120225.pdf
chapter8-stack-161018120225.pdfchapter8-stack-161018120225.pdf
chapter8-stack-161018120225.pdf
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 

More from Jay Patel

More from Jay Patel (12)

Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)
 
Cursor
CursorCursor
Cursor
 
Anchored data type
Anchored data typeAnchored data type
Anchored data type
 
Selection sort
Selection sortSelection sort
Selection sort
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Sound
SoundSound
Sound
 
Images
ImagesImages
Images
 
Cursor
CursorCursor
Cursor
 
Codd rules
Codd rulesCodd rules
Codd rules
 
Codd rules
Codd rulesCodd rules
Codd rules
 
Presentation1
Presentation1Presentation1
Presentation1
 

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Stack Operations and Applications

  • 1. S T A C www.eshikshak.co.in K
  • 2. INTRODUCTION ● Array allows to insert and delete an element at any place in the list ● STACK is a list of elements ● It is a linear data structure ● Insertion and deletion operation is performed only at one end – known as top of stack ● Also known as Last-in-First-out (LIFO), entries are removed in reverse order of insertion www.eshikshak.co.in
  • 3. BASIC OPERATIONS OF STACKS ● push -- insert item on stack ● pop -- remove item from stack ● peek -- examine, but don’t remove item ● isEmpty – reports whether or not stack is empty ● isFull- reports whether or not stack is full ● size – returns # of items in stack www.eshikshak.co.in
  • 4. PUSH OPERATION ● Inserting element in a stack is known as PUSH ● When elements are inserted continuously to the stack it grows at one end i.e. top Top 9 => Top 6 8 => Top -7 -7 -7 => Top 8 8 8 8 => Top 5 5 5 5 5 => Top = NULL www.eshikshak.co.in
  • 5. POP OPERATION ● Removing of element from a stack is known as pop ● When elements are removed continuously from a stack, it shrinks at the same end i.e. top Top 9 => 8 Top 6 => -7 -7 Top -7 => 8 8 8 Top 8 => 5 5 5 5 Top 5 => Top = NULL www.eshikshak.co.in
  • 6. STACKS CONDITIONS ● Depending on implementation, ● Important to know if stack is may be necessary to check if empty -- attempt to remove an stack is full -- attempt to add item from an empty stack is an item to a full stack is an overflow underflow error. error Top 9 => 8 -7 8 5 Top = NULL www.eshikshak.co.in
  • 7. PUSH(STACK, TOP, MAXSTK, ITEM) STACK - Linear Array, TOP – location of top element in stack, MAXSTK – Numbers of elements that be stored in Stack, ITEM – value that has to be inserted in stack STEP 1. if top = MaxStk, then print “Overflow” and return STEP 2. set top=top + 1 STEP 3. set STACK[top] = item STEP 4. Return www.eshikshak.co.in
  • 8. PUSH(STACK, TOP) STACK - Linear Array, TOP – location of top element in stack, ITEM – value that has to be inserted in stack 1. [check for underflow of the stack] if TOP=-1 then Write(“stack underflow on pop) end if 2. [ Assign the top element of the stack to ITEM] ITEM = STACK[TOP] 2. [decrement pointer] TOP=TOP-1 3. [return former top element of the stack] Return(ITEM) 4. Exit www.eshikshak.co.in
  • 9. PEEP(STACK,TOP) 1. [check for stack underflow] if TOP-I+1<=0 then Write (“stack underflow on peep”) end if 2. [Return the top element of the stack] Return(stack[TOP-MAX+1]) 3. Exit www.eshikshak.co.in
  • 10. APPLICATIONS OF STACK ● Undo ● Redo ● Function Call ● Recursive Function Call ● Convert infix to Postfix expression ● Convert infix to Prefix expression ● Evaluate infix expression ● Tower of hanoi ● Reverse string or list or file www.eshikshak.co.in