SlideShare una empresa de Scribd logo
1 de 10
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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
 

Destacado (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 a Stack Operations and Applications

Similar a 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
 

Más de Jay Patel

Más de 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
 

Último

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
[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
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Último (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[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
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

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