SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler 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

Mais conteúdo relacionado

Destaque

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
 

Destaque (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
 

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

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

Mais de Jay Patel

Mais 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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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)
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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