Xii Stack
Xii Stack
For example
stu={1:56,2:45,3:78,4:65,5:35,6:90}
values of stack_roll and stack_mark after push_stu()
[3,4,6] and {78,65,90}
2. A List contains following record of a Book :
[Book Name, Write Name, Price]
Write the following user defined functions to perform given operations on the stack named “BOOK” :
(i) Push_Rec( ) – To push the record containing Book name and author name of Books having price >
500 to the stack.
(ii) Pop_Rec( ) – To pop the objects from the stack and display them. Also display “STACK
UNDERFLOW” when there are no elements in the Stack.
3. A list contains following record of a student:
[student_name, marks, subject]
Write the following user defined functions to perform given operations on the stack named ‘status’:
(i) Push_element() - To Push an object containing name and marks of a student who scored more than
75 marks in ‘CS’ 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 customer details are:
[“Danish”,80,”Maths”]
[“Hazik”,79,”CS”]
[“Parnik”,95,”Bio”]
[“Danish”,70,”CS”]
[“Sidhi”,99,”CS”]
The stack should contain
[“Hazik”,”79”]
[“Sidhi”,”99”]
The output should be:
[“Hazik”,”79”]
[“Sidhi”,”99”]
Stack Empty
4. 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.
5. Alam has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the given operations based on this list.
(a) Traverse the content of the list and push the even numbers into a stack.
(b) Pop and display the content of the stack.
For example, If the sample content of the list is as follows
N = [12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
38 2 98 56 34 12
6. Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a
program, with separate user defined functions to perform the following operations.
(a) Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
(marks) is greater than 75.
(b) Pop and display the content of the stack. For example If the sample content of the dictionary is as
follows
R={“OM”:76, “JAI”:45, “BOB”:89, “ALI”:65, “ANU”:90, “TOM”:82}
The output from the program should be
TOM ANU BOB OM
7. Two list Lname and Lage contains name of person and age of person respectively. A list named
Lnameage is empty. Write functions as details given below
(i) Push_na() :- it will push the tuple containing pair of name and age from Lname and Lage whose age
is above 50
(ii) Pop_na() :- it will remove the last pair of name and age and also print name and age of removed
person. It should also print “underflow” if there is nothing to remove