0% found this document useful (0 votes)
3 views

12 Stack

A stack is a linear data structure that follows the Last In First Out (LIFO) principle, where elements can only be added or removed from the top. The main operations are PUSH (to add an element) and POP (to remove an element), with additional functionality to inspect the top element without removal (Peek). Errors such as Overflow and Underflow occur when trying to add to a full stack or remove from an empty stack, respectively.

Uploaded by

sathyaa.m1720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

12 Stack

A stack is a linear data structure that follows the Last In First Out (LIFO) principle, where elements can only be added or removed from the top. The main operations are PUSH (to add an element) and POP (to remove an element), with additional functionality to inspect the top element without removal (Peek). Errors such as Overflow and Underflow occur when trying to add to a full stack or remove from an empty stack, respectively.

Uploaded by

sathyaa.m1720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

DATA STRUCTURES

STACK
CHAP 9
DATA STRUCTURE
Data structure refers to a data
collection with well defined
operations and behavior or
properties.
Stack
• A stack is a linear structure
implemented in LIFO (Last In
First Out) manner where
insertions and deletions are
restricted to occur only at one
end – stack’s top.
Rules to be
followed:
• Data can only be removed
from the top ( pop), i.e., the
element at the top of the
stack. the removal of element
from a stack is technically
called as POP operation.
Rules to be
followed:
• A new element can only
be added to the top of the
stack ( push). the insertion
of element in a stack is
technically called PUSH
operation.
PUSH & POP
Peek

• Refers to inspecting the


value at the stack's top
without removing it. it is
also sometimes referred as
inspection.
Overflow
Overflow Top

• Overflow refers to the situation


(ERROR) when one tries to
push an item in stack that is
full.
• This situation occurs when the
size of the stack is fixed and
cannot grow further or there is
no memory left to
accommodate new item.

Stack
• Underflow refers to situation (ERROR) when
one tries to pop/delete an item from an
Underflow empty stack.
• That is stack is currently having no item and
still one tries to pop an item
Implementing stack in Python
• Peak
<stack>[top]
• Push
<stack>.append(<item>)
• Pop
<stack>.pop()

You might also like