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

PL - 7 Data Structure

The document outlines a series of practical programming exercises focused on implementing stack data structures in Python using lists. Each exercise requires the creation of functions for PUSH and POP operations, along with additional functionalities such as displaying stack contents and handling specific conditions for various data types including integers, strings, and custom objects like books. The exercises are designed to reinforce understanding of stack operations through menu-driven programs and specific data handling scenarios.

Uploaded by

bludoggo2008
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 views2 pages

PL - 7 Data Structure

The document outlines a series of practical programming exercises focused on implementing stack data structures in Python using lists. Each exercise requires the creation of functions for PUSH and POP operations, along with additional functionalities such as displaying stack contents and handling specific conditions for various data types including integers, strings, and custom objects like books. The exercises are designed to reinforce understanding of stack operations through menu-driven programs and specific data handling scenarios.

Uploaded by

bludoggo2008
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

Practical List : 7

Data Structure

1 Write a menu driven program to implement a stack with the help of a list of integers. Use separate
functions for performing PUSH and POP operations. POP operation should display “Stack is
EMPTY” message, if the list acting as a stack contains nothing in it. Call both the functions, with
the help of menu driven options.
2 Given the following expected information of a list Book,
●​ Code of type integer
●​ Title of the type string

Write a menu driven program to implement a stack of Book having two separate functions to perform
PUSH and POP operations.
3 Write a Python code with the following functions in Python
●​ PUSH(ITEMLIST,ST), where ITEMLIST is a nested list of lists containing INO (an integer), ITEM(a
string), QTY(an integer). From this list, push all lists in Stack ST, which have QTY<10.
●​ POP(ST), to remove and return an item from the top of STACK and should return a string with the
content as “No reorder ITEM” when there are no more items left in ST to be popped.
●​ DISPLAY(ST), to display the content of the stack if it has at least one element, otherwise display an
appropriate error message as “No reorder ITEM”. Also,

●​ Initialize ITEMLIST with at least 5 items


●​ Call PUSH function
●​ Give menu driven options to the user to call POP and DISPLAY functions in a loop till the time POP
does not return a message as “No reorder ITEM”
4 Write functions in Python (i) PUSH(N) to add new names (strings) as stack (ii) POP(N) to remove names
from N as in stack and (iii) SHOW(N) to display content of N. Here N is a stack implemented by a list of
names (strings).
Call the above functions using menu driven options in a loop.

5 Write a Python program to :


●​Define a function PushCities(C, N) to Push the city name N into a List implemented stack named
C.
●​ Define a function PopCities(C) to Pop and display the last city name from the stack C. The
function should display the message “Empty Stack” if stack C does not have any value in it.
●​Define a function ShowCities(C) to display the content of the stack C.
Consider the following:
Long=[]
Cities=["KOLKATA", "MUMBAI", "LUCKNOW", "GOA", "BENGALURU"]
a.​ Push only those city names from Cities which have length of more than 5 characters into the list
Long, with the help of PushCities() function
b.​ Display the content of stack Long with the help of ShowCities() function
c.​ Pop all the elements from Long, one after another with PopCities() function till the stack becomes
empty
6 Write a Python program to :
●​ Define a function PushMarks(M,N) to Push Mark N of a student into a List implemented stack M.
●​ Define a function PopMarks(M) to Pop and display the last value from the stack M. The function
should display the message “Empty Stack” if the stack M does not have any value in it.
●​ Define a function ShowMarks(M) to display the content of the stack M.
Consider the following:
Toppers=[]
Marks=[95, 92, 75, 80, 93, 45, 98, 78]
a.​ Push only Marks which are more than 90 from Marks into the list Toppers, with the help of
PushMarks() function
b.​ Display the content of stack Toppers with the help of ShowMarks() function
c. Pop all the elements from Toppers, one after another with PopMarks() function till the stack becomes
empty

7 Write a Python program to :


●​ Define a function PushNames(S,N) to Push a Name N into the List implemented stack S.
●​ Define a function PopNames(S) to Pop and display the last Name from the stack S. The function
should display the message “Empty Stack” if stack S does not have any value in it.
●​ Define a function ShowNames(S) to display the content of the stack S.
Consider the following:
OnlyA=[]
Names=["AMAR", "ASHWIN", "NITIN", "JASON", "ARSALAN","PRIYA","ANU"]
a.​ Push only the Names beginning with letter A from Names into the list OnlyA, with the help of
PushNames() function
b.​ Display the content of stack OnlyA with the help of ShowNames() function
c. Pop all the elements from OnlyA, one after another with PopNames() function till the stack becomes
empty

8 Write a Python program to :


●​ Define a function Pushint(S,N) to Push an integer N into the List implemented stack S.
●​ Define a function Popint(S) to Pop and display the last integer from the stack S. The function should
display the message “Empty Stack” if stack S does not have any value in it.
●​ Define a function Show(S) to display the content of the stack S.
Consider the following:
S=[]
L=[12,56,43,23,78,65,34,23]
a.​ Push only Even values from L into the list S, with the help of Pushint(S,n) function
b.​ Display the content of stack S with the help of Show(S) function
C. Pop all the elements from S, one after another with Popint(S) function till the stack becomes empty

You might also like