SlideShare ist ein Scribd-Unternehmen logo
1 von 21
STACK AND ITS OPERATIONS
Mrs.G.Chandraprabha,M.Sc.,M.Phil.,
Assistant Professor,
Department of Information Technology,
V.V.Vanniaperumal College for Women,
Virudhunagar.
STACK - INTRODUCTION
 A stack is an Abstract Data Type (ADT), commonly used in
most programming languages.
 It is named stack as it behaves like a real-world stack, for
example – a deck of cards or a pile of plates, etc.
 A real-world stack allows operations at one end only. For
example, we can place or remove a card or plate from the
top of the stack only.
 Likewise, Stack ADT allows all data operations at one end
only. At any given time, we can only access the top element
of a stack.
STACK - DEFINITION
 Stack is an example of Linear data structure which follows the
LIFO order.
 LIFO stands for Last-in-first-out.
 Here, the element which is placed (inserted or added) at end
is accessed at first.
 Both insertion and deletion can be done in one end whic
 In stack terminology, insertion operation is
called PUSH operation and removal operation is
called POP operation.
STACK - DEFINITION
STACK - EXAMPLE
1.Deck of Cards
2.Arranging plates
STACK - REPRESENTATION
 A stack may be represented in the memory in various ways.
There are two main ways: using a one-dimensional array and a
single linked list.
 Array Representation of Stacks: First we have to allocate a
memory block of sufficient size to accommodate the full capacity
of the stack. Then, starting from the first location of the memory
block, the items of the stack can be stored in a sequential fashio
 In Figure, Itemi denotes the ith item in the stack; l and u denote
the index range of the array in use; usually the values of these
indices are 1 and SIZE respectively.
STACK - REPRESENTATION
 TOP is a pointer to point the position of the array up to which it
is filled with the items of the stack. With this representation,
the following two ways can be stated:
 EMPTY: TOP < l
FULL: TOP ≥ u
 Linked List Representation of Stacks: Although array
representation of stacks is very easy and convenient but it
allows the representation of only fixed sized stacks. In several
applications, the size of the stack may vary during program
execution.
STACK - REPRESENTATION
 An obvious solution to this problem is to represent a stack using
a linked list.
 A single linked list structure is sufficient to represent any stack.
 Here, the DATA field is for the ITEM, and the LINK field is, as
usual, to point to the next' item.
 In the linked list representation, the first node on the list is the
current item that is the item at the top of the stack and the last
node is the node containing the bottom-most item.
 Thus, a PUSH operation will add a new node in the front and a
POP operation will remove a node from the front of the list.
STACK - REPRESENTATION
OPERATIONS ON STACK
 A stack is used for the following two primary operations,
 push() − Pushing (storing) an element on the stack.
 pop() − Removing (accessing) an element from the
stack.
 When data is PUSHed onto stack.
 To use a stack efficiently, we need to check the status of stack
as well. For the same purpose, the following functionality is
added to stacks −
 peek() − get the top data element of the stack, without
removing it.
 isFull() − check if stack is full.
 isEmpty() − check if stack is empty.
PUSH OPERATION
 The process of putting a new data element onto
stack is known as a Push Operation. Push
operation involves a series of steps −
 Step 1 − Checks if the stack is full.
 Step 2 − If the stack is full, produces an error and
exit.
 Step 3 − If the stack is not full, increments top to
point next empty space.
 Step 4 − Adds data element to the stack location,
where top is pointing.
 Step 5 − Returns success.
PUSH OPERATION – ARRAY ALGORITHM
PUSH OPERATION – EXAMPLE
POP OPERATION
 Removing an element from the stack, is known as a Pop
Operation. In an array implementation of pop() operation, the
data element is not actually removed, instead top is
decremented to a lower position in the stack to point to the
next value. But in linked-list implementation, pop() actually
removes data element and deallocates memory space.
 A Pop operation may involve the following steps −
 Step 1 − Checks if the stack is empty.
 Step 2 − If the stack is empty, produces an error and exit.
 Step 3 − If the stack is not empty, accesses the data element
at which top is pointing.
 Step 4 − Decreases the value of top by 1.
 Step 5 − Returns success.
POP OPERATION – ARRAY ALGORITHM
POP OPERATION - EXAMPLE
STATUS_ARRAY OPERATION - ALGORITHM
 Status_Array , we test the various states of a stack such as
whether it is full or empty, how many items are right now in
it, and read the current element at the top without
removing it, etc.
PUSH OPERATION - LINKED LIST ALGORITHM
POP OPERATION - LINKED LIST ALGORITHM
STATUS OPERATION - LINKED LIST ALGORITHM
THANKYOU

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Radial Basis Function Networks
Introduction to Radial Basis Function NetworksIntroduction to Radial Basis Function Networks
Introduction to Radial Basis Function Networks
ESCOM
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
Ashim Saha
 
Hebbian Learning
Hebbian LearningHebbian Learning
Hebbian Learning
ESCOM
 

Was ist angesagt? (20)

Stacks
StacksStacks
Stacks
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Sparse matrix
Sparse matrixSparse matrix
Sparse matrix
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Stack
StackStack
Stack
 
Adjacency And Incidence Matrix
Adjacency And Incidence MatrixAdjacency And Incidence Matrix
Adjacency And Incidence Matrix
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Data Structure
Data Structure Data Structure
Data Structure
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Arrays searching-sorting
Arrays searching-sortingArrays searching-sorting
Arrays searching-sorting
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 
Introduction to Radial Basis Function Networks
Introduction to Radial Basis Function NetworksIntroduction to Radial Basis Function Networks
Introduction to Radial Basis Function Networks
 
Splay Tree
Splay TreeSplay Tree
Splay Tree
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
Hebbian Learning
Hebbian LearningHebbian Learning
Hebbian Learning
 
Expression trees
Expression treesExpression trees
Expression trees
 

Ähnlich wie Stack and its operations

Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 

Ähnlich wie Stack and its operations (20)

Stack
StackStack
Stack
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Stack
StackStack
Stack
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Stack organization
Stack organizationStack organization
Stack organization
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
04 stacks
04 stacks04 stacks
04 stacks
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Ds
DsDs
Ds
 
Lecture5
Lecture5Lecture5
Lecture5
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
 

Mehr von V.V.Vanniaperumal College for Women

Mehr von V.V.Vanniaperumal College for Women (20)

Control Memory.pptx
Control Memory.pptxControl Memory.pptx
Control Memory.pptx
 
ADDRESSING MODES.pptx
ADDRESSING MODES.pptxADDRESSING MODES.pptx
ADDRESSING MODES.pptx
 
Data_Transfer&Manupulation Instructions.pptx
Data_Transfer&Manupulation Instructions.pptxData_Transfer&Manupulation Instructions.pptx
Data_Transfer&Manupulation Instructions.pptx
 
Timing & Control.pptx
Timing & Control.pptxTiming & Control.pptx
Timing & Control.pptx
 
Human Rights - 1.pptx
Human Rights - 1.pptxHuman Rights - 1.pptx
Human Rights - 1.pptx
 
Registers.pptx
Registers.pptxRegisters.pptx
Registers.pptx
 
Instruction Codes.pptx
Instruction Codes.pptxInstruction Codes.pptx
Instruction Codes.pptx
 
Features of Java.pptx
Features of Java.pptxFeatures of Java.pptx
Features of Java.pptx
 
JVM.pptx
JVM.pptxJVM.pptx
JVM.pptx
 
Constructors in JAva.pptx
Constructors in JAva.pptxConstructors in JAva.pptx
Constructors in JAva.pptx
 
IS-Crypttools.pptx
IS-Crypttools.pptxIS-Crypttools.pptx
IS-Crypttools.pptx
 
IS-Delibrate software attacks.pptx
IS-Delibrate software attacks.pptxIS-Delibrate software attacks.pptx
IS-Delibrate software attacks.pptx
 
IS-Nature of forces.ppt
IS-Nature of forces.pptIS-Nature of forces.ppt
IS-Nature of forces.ppt
 
IS-cryptograpy algorithms.pptx
IS-cryptograpy algorithms.pptxIS-cryptograpy algorithms.pptx
IS-cryptograpy algorithms.pptx
 
IS-Types of IDPSs.pptx
IS-Types of IDPSs.pptxIS-Types of IDPSs.pptx
IS-Types of IDPSs.pptx
 
IS-honeypot.pptx
IS-honeypot.pptxIS-honeypot.pptx
IS-honeypot.pptx
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
 
M-coloring.pptx
M-coloring.pptxM-coloring.pptx
M-coloring.pptx
 
storm.ppt
storm.pptstorm.ppt
storm.ppt
 
storm for RTA.pptx
storm for RTA.pptxstorm for RTA.pptx
storm for RTA.pptx
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Stack and its operations

  • 1. STACK AND ITS OPERATIONS Mrs.G.Chandraprabha,M.Sc.,M.Phil., Assistant Professor, Department of Information Technology, V.V.Vanniaperumal College for Women, Virudhunagar.
  • 2. STACK - INTRODUCTION  A stack is an Abstract Data Type (ADT), commonly used in most programming languages.  It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc.  A real-world stack allows operations at one end only. For example, we can place or remove a card or plate from the top of the stack only.  Likewise, Stack ADT allows all data operations at one end only. At any given time, we can only access the top element of a stack.
  • 3. STACK - DEFINITION  Stack is an example of Linear data structure which follows the LIFO order.  LIFO stands for Last-in-first-out.  Here, the element which is placed (inserted or added) at end is accessed at first.  Both insertion and deletion can be done in one end whic  In stack terminology, insertion operation is called PUSH operation and removal operation is called POP operation.
  • 5. STACK - EXAMPLE 1.Deck of Cards 2.Arranging plates
  • 6. STACK - REPRESENTATION  A stack may be represented in the memory in various ways. There are two main ways: using a one-dimensional array and a single linked list.  Array Representation of Stacks: First we have to allocate a memory block of sufficient size to accommodate the full capacity of the stack. Then, starting from the first location of the memory block, the items of the stack can be stored in a sequential fashio  In Figure, Itemi denotes the ith item in the stack; l and u denote the index range of the array in use; usually the values of these indices are 1 and SIZE respectively.
  • 7. STACK - REPRESENTATION  TOP is a pointer to point the position of the array up to which it is filled with the items of the stack. With this representation, the following two ways can be stated:  EMPTY: TOP < l FULL: TOP ≥ u  Linked List Representation of Stacks: Although array representation of stacks is very easy and convenient but it allows the representation of only fixed sized stacks. In several applications, the size of the stack may vary during program execution.
  • 8. STACK - REPRESENTATION  An obvious solution to this problem is to represent a stack using a linked list.  A single linked list structure is sufficient to represent any stack.  Here, the DATA field is for the ITEM, and the LINK field is, as usual, to point to the next' item.  In the linked list representation, the first node on the list is the current item that is the item at the top of the stack and the last node is the node containing the bottom-most item.  Thus, a PUSH operation will add a new node in the front and a POP operation will remove a node from the front of the list.
  • 10. OPERATIONS ON STACK  A stack is used for the following two primary operations,  push() − Pushing (storing) an element on the stack.  pop() − Removing (accessing) an element from the stack.  When data is PUSHed onto stack.  To use a stack efficiently, we need to check the status of stack as well. For the same purpose, the following functionality is added to stacks −  peek() − get the top data element of the stack, without removing it.  isFull() − check if stack is full.  isEmpty() − check if stack is empty.
  • 11. PUSH OPERATION  The process of putting a new data element onto stack is known as a Push Operation. Push operation involves a series of steps −  Step 1 − Checks if the stack is full.  Step 2 − If the stack is full, produces an error and exit.  Step 3 − If the stack is not full, increments top to point next empty space.  Step 4 − Adds data element to the stack location, where top is pointing.  Step 5 − Returns success.
  • 12. PUSH OPERATION – ARRAY ALGORITHM
  • 14. POP OPERATION  Removing an element from the stack, is known as a Pop Operation. In an array implementation of pop() operation, the data element is not actually removed, instead top is decremented to a lower position in the stack to point to the next value. But in linked-list implementation, pop() actually removes data element and deallocates memory space.  A Pop operation may involve the following steps −  Step 1 − Checks if the stack is empty.  Step 2 − If the stack is empty, produces an error and exit.  Step 3 − If the stack is not empty, accesses the data element at which top is pointing.  Step 4 − Decreases the value of top by 1.  Step 5 − Returns success.
  • 15. POP OPERATION – ARRAY ALGORITHM
  • 16. POP OPERATION - EXAMPLE
  • 17. STATUS_ARRAY OPERATION - ALGORITHM  Status_Array , we test the various states of a stack such as whether it is full or empty, how many items are right now in it, and read the current element at the top without removing it, etc.
  • 18. PUSH OPERATION - LINKED LIST ALGORITHM
  • 19. POP OPERATION - LINKED LIST ALGORITHM
  • 20. STATUS OPERATION - LINKED LIST ALGORITHM