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

Stack Practice Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Stack Practice Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1 Write a function AddCustomer(Customer) in Python to add a new Customer information into the

stack (list) CStack and display the information.

2 Write a function DeleteCustomer() to delete a Customer information from a list of


CStack. The function delete the name of customer from the stack.
Example: If the stack contains [“Abhinav”,”Vimank”],
the output should be:
Vimank
Abhinav

3 A list contains following record of a student: [Rno, Name, Dob, Class]


Write the following user defined functions to perform given operations
on the stack named ‘status’:
(i) Push_element() - To Push an record of student to the stack
(ii) Pop_element() - To Pop the objects from the stack and display them. Also, display “Stack
Empty” when there are no elements in the stack.

4 Write a function in Python, Push(book) where, book is a dictionary containing the details of a
book in form of {bookno : price}.
The function should push the book in the stack which have price greater than 300. Also display
the count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Dbook={"Python":350,"Hindi":200,"English":270,"Physics":600, “Chemistry”:550}
The stack should contain
Chemistry
Physics
Python
The output should be:
The count of elements in the stack is 3

5 Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book and
delete a Book from a List of Book titles, considering them to act as push and pop
operations of the Stack data structure.

6 Write a program to implement a stack for the students(studentno, name). Just


implement Pop and display.

7 Write a function in python, pushme (stock, item) and popme(stock ) to add a new
item and delete an item from the stock, considering them to act as push and pop
operations of the stack.

8 Pramod has created a dictionary containing EMPCODE and SALARY as key value pairs of 5
Employees of Parthivi Constructions.
Write a program, with separate user defined functions to perform the following operations:
● Push the keys (Employee code) of the dictionary into a stack, where the corresponding value
(Salary) is less than 25000.
● Pop and display the content of the stack. For example: If the sample content of the dictionary is
as follows:
EMP={"EOP1":16000, "EOP2":28000, "EOP3":19000, "EOP4":15000, EOP5":30000}
3
The output from the program should be: EOP4 EOP3 EOP1

9 Write a function in Python PushBook(Book) to add a new book entry as book_no and book_title
in the list of Books , considering it to act as push operations of the Stack data structure.
Write a function in Python PopBook(Book), where Book is a stack implemented by a list of
books. The function returns the value deleted from the stack

10 A dictionary contains records of a tourist place like :


Tour_dict = { ‘Name’: ‘Goa’ , ‘PeakSeason’ : ‘December’ , ‘Budget’ : 15000 ,
‘Famous’:’Beaches’}
Write the following user defined functions to perform given operations on the stack named
‘tour’:
(i) Push_tour( Tour_dict) – To Push a list containing values for Name and PeakSeason where
value of budget is less than 10000 into the tour stack
(ii) Pop_tour() – To Pop the list objects from the stack and display them. Also, display “No
more tours” when there are no elements in the stack.
For example if the following dictionaries are passed to Push_tour( ) function in the following
sequence:
{ ‘Name’: ‘Goa’ , ‘PeakSeason’ : ‘December’ , ‘Budget’ : 15000 , ‘Famous’:’Beaches’}
{ ‘Name’: ‘Nainital’ , ‘PeakSeason’ : ‘May’ , ‘Budget’ : 9000 , ‘Famous’:’Nature’}
{ ‘Name’: ‘Sikkim’ , ‘PeakSeason’ : ‘May’ , ‘Budget’ : 9500 , ‘Famous’:’Mountains’}
{ ‘Name’: ‘Kerala’ , ‘PeakSeason’ : ‘November’ , ‘Budget’ : 15000 , ‘Famous’:’Back Waters’}
{ ‘Name’: ‘Orissa’ , ‘PeakSeason’ : ‘January’ , ‘Budget’ : 8000 , ‘Famous’:’Temples’}
Then the stack ‘tour’ will contain :
[ ‘Orrisa’ , ‘January’]
[‘Sikkim’, ‘May’]
[‘Nainital’ ,’ May’]
The output produced when calling pop_tour( ) function should be :
[ ‘Orrisa’ , ‘January’]
[‘Sikkim’, ‘May’]
[‘Nainital’ ,’ May’]
No more tours

11 Mr.Ajay has created a list of elements. Help him to write a program in python with functions,
PushEl(element) and PopEl(element) to add a new element and delete an element from a List of
element Description, considering them to act as push and pop operations of the Stack data
structure
. Push the element into the stack only when the element is divisible by 4.
For eg:if L=[2,5,6,8,24,32]
then stack content will be 32 24 8

12 Write a function in Python, Push(KItem), where KItem is a dictionary


containing the details of Kitchen items– {Item:price}.
The function should push the names of those items in a stack which have price
less than 100. Also display the average price of elements pushed into the
stack.
For example: If the dictionary contains the following data:
{"Spoons":116,"Knife":50,"Plates":180,"Glass":60}
The stack should contain
Glass
Knife
The output should be:
The average price of an item is 55.0

13 A list contains following record of a doctor:


[Doc_ID, Doc_name, Phone_number, Speciality]
Write the following user defined functions to perform given operations on
the stack named "status":
(i) Push_element() - To Push an object containing Doc_ID and Doc_name
of doctors who specialize in Anesthesia to the stack.
(ii) Pop_element() - To Pop the objects from the stack and display them.
Also, display “Stack Empty” when there are no elements in the stack.
For example: If the lists of Doctors' details are:
['D01', "Gurdas", “99999999999”,"Anesthesia”]
["D02", "Julee", “8888888888”,"cardiology"]
["D03",“Murugan”,”77777777777”,”Anesthesia”]
["D04",“Ashmit”, “1010101010”,”Medicine”]
The stack should contain
['D03', 'Murugan']
['D01', 'Gurdas']
The output should be:
['D03', 'Murugan']
['D01', 'Gurdas']
Stack Empty

14 A list contains following record of a student:


[StudentName, Class, Section, MobileNumber]
Write the following user defined functions to perform given operations on the stack named ‘xiia’:
(i) pushElement() - To Push an object containing name and mobile number of students who
belong to class xii and section ‘a’ to the stack
(ii) popElement() - To Pop the objects from the stack and display them. Also, display “Stack
Empty” when there are no elements in the stack.
For example:
If the lists of students details are:
[“Rajveer”, “99999999999”,”XI”, “B”]
[“Swatantra”, “8888888888”,”XII”, “A”]
[“Sajal”,”77777777777”,”VIII”,”A”]
[“Yash”, “1010101010”,”XII”,”A”]
The stack “xiia” should contain
[“Swatantra”, “8888888888”]
[“Yash”, “1010101010”]
The output should be:
[“Yash”, “1010101010”]
[“Swatantra”, “8888888888”]
Stack Empty

15 Write a function in Python, Push(SItem) where, SItem is a dictionary containing the details of
stationary items– {Sname:price}.
The function should push the names of those items in the stack who have price greater than 25.
Also display the count of elements pushed into the stack.
For example:
If the dictionary contains the following data
Ditem = {“Rubber”:5, "Pencil":5, "Pen":30, "Notebook": 60, "Eraser":5, “Watch”: 250}
The stack should contain
Pen
Notebook
Watch
The output should be:
The count of elements in the stack is 3

You might also like