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

Data Structure in Python

Uploaded by

neerajkanta123
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)
12 views2 pages

Data Structure in Python

Uploaded by

neerajkanta123
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

Ch - Data structures :- Stack

=================================================
Data structures :->
It represents how data is stored / organized in the computer's memory. In python, data
structures can be implemented through various techniques like linear list, stack, queue,
numpy, pandas etc.

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

Operation on Stack=>
There are mainly two types of operations that can be performed on stack.
i) push :-
Insertion of an element on the top of stack is called push operation.

ii) pop :-
Removal of an element from the top of stack is called pop operation.

overflow and underflow case:-


overflow:--->
It refers a situation, when one tries to push an element in stack, that is full.
(in python, stack is implemented through list and list is growable in nature that's why
overflow condition doesn't arise.)
underflow:---->
It refers a situation, when one tries to delete an element from the empty stack.
--------------------------------------------------------------
STACK

17. WAP in Python to insert even elements from L=[24,7,45,8,19,10] into a list
named evenL. The program should then repeatedly delete and display the
elements from evenL. The insertion and deletion should be implemented with
the help of function namely pushEven() and popEven() to represent Push and
Pop operations of stack.
Output:
10
8
24
Underflow!
18. WAP in Python to store book titles in a List named title. The program
should repeatedly delete and display the book titles that are 4 characters long.
The store and delete operations should be implemented with the help of
functions addBook() and removeBook() as Push and Pop operations of Stack.
Example input:
If title=[‘Java’,’C++’,’DBMS’,’Python’]
Output:
DBMS
Java
Underflow!

19. WAP in Python to insert the names of the students who have scored more
than 90 from d, where d is:
d={‘Aditya’:95,’Karan’:88,’Khushi’:91,’Riya’:82,’Vikash’:96}, , into a list named
CSgt90.
The program should then delete and display all the names of the students
scoring more than Ninety.
The insertion and deletion operations to be implemented with the help of
functions namely gtNinety() and display() , representing Push and Pop
operations of stack respectively.
Output:
Vikash l
Khushi
Aditya
Underflow!!!

20. Write a menu driven program to implement the following Stack operations
in a List: push, pop, peek and display using functions.

You might also like