04 Data Structures (Stack)
04 Data Structures (Stack)
6. What is a stack?
Ans. Stack is a basic data structure where insertion and deletion of data
takes place at one end called the top of the stack i.e., it follows the Last in
First Out(LIFO) principle.
7. Sunita has created a nested list : “KidsData”, storing data of kids. Write
these functions:
(a) Push_Kids(KidsData, Stack): The function checks the details in the list
and pushes Kid Id and Name to the Stack, only if the kids are of “Nursery”
(b) Pop_Kids(Stack): The function removes the elements and print them
from the stack. Also display “Stack Empty” when stack is empty.
List Structure:
KidsData = [[KidID, Kidname, Age, Grade]]
10. Given a stack named "movies", write a Python program with two user-
defined functions:
(a) Add_Movie(movie_details, movies): This function takes a nested list of
movie details and adds title and genre to the stack only if the rating is above
7.
(b) Remove_Movie(movies) : This function removes and displays the
elements from the stack. Also, print “Stack Empty” When Stack is empty.
The structur of movie_details is:
Movie_details = [[title, genre, rating], ----------------]