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-phpapp01
Jay Patel
 
Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01
Jay Patel
 
Web01 091024130908-phpapp01
Web01 091024130908-phpapp01Web01 091024130908-phpapp01
Web01 091024130908-phpapp01
Jay Patel
 
Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01
Jay 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 hypermedia
Jay 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 tools
Jay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
Jay 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 Lecturestacks 110802115132-phpapp02

Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
Kumar
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 

Similar to Lecturestacks 110802115132-phpapp02 (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

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Recently uploaded (20)

Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 

Lecturestacks 110802115132-phpapp02

  • 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