0% found this document useful (0 votes)
4 views2 pages

STACK

This document explains the concept of data structures, specifically focusing on stacks, which are linear data structures that operate on a Last In First Out (LIFO) principle. It details the main operations of stacks, namely Push (inserting an element) and Pop (removing an element), along with conditions for stack overflow and underflow. Additionally, it provides a simple implementation of a stack using a list in Python.

Uploaded by

ammaarakheel
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)
4 views2 pages

STACK

This document explains the concept of data structures, specifically focusing on stacks, which are linear data structures that operate on a Last In First Out (LIFO) principle. It details the main operations of stacks, namely Push (inserting an element) and Pop (removing an element), along with conditions for stack overflow and underflow. Additionally, it provides a simple implementation of a stack using a list in Python.

Uploaded by

ammaarakheel
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/ 2

CHAPTER 3

STACK
Data structure :
A Data Structure is a group of data that have different data types which can be accessed
as a unit .
A data structure has well-defined operations , behaviour and properties.

CLASSIFICATION OF DATA STRUCTURES


1.Linear Data Structures
A data structure in which elements are organized in a sequence is called linear data
structure. Eg: stack , queue, array, linked list
2.Non Linear Data Structures
These are multilevel data structures. Eg. Tree , graph

STACK
• Stack is a linear data structure
• Stack is a list of elements in which an element may be inserted or deleted only at
one end called the Top of the stack.
• It follows the principle Last In First Out (LIFO). LIFO means the element
inserted last would be the first to be deleted.

Operations on Stack
There are mainly two types of operations that can be done with stack
1. Push 2. Pop
Push : Insertion of an element on top of the stack is called Push.
Pop : Removal of an element from the top of the stack is called POP.
Note: Push and Pop operations are done from single end called TOP
Eg: Suppose a list of 5 items to be inserted in the stack .

2
Push 9 9
operation 4 4 4
56 56 56 56
24 24 24 24 24
Push 24 Push 56 Push 4 Push 9 Push 2 Stack
overflow
Maya Giby
PGT Computer Sc
2
Pop 9 9
operation 4 4 4
56 56 56 56
24 24 24 24 24
Pop Pop Pop Pop Pop Stack
underflow

Stack Overflow: It refers to a situation , when one tries to push an element in stack, that
is full .(Stacks are list implemented , since list can grow, overflow condition does not
arise until all memory is exhausted.
Stack Underflow : It refers to a situation when one tries to pop an item from an empty
stack .

#implementation of stack using List


stack =[]
while True:
print("1.PUSH")
print("2.POP")
print("3.Display elements of stack")
choice=int(input("Enter your choice"))
if choice == 1:
a=int(input("Enter the element which you want to push"))
stack.append(a)
elif choice == 2:
if stack == []:
print("Stack is empty...Underflow case...")
else:
print("Deleted element is :", stack.pop())
elif choice == 3:
print("The elements in the stack =", stack)
else:
print("Wrong input...")
ch = input("Do you want to continue or not(y/n) ?")
if ch in 'nN':
break

Maya Giby
PGT Computer Sc

You might also like