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

stack

Stack question class 12 practice

Uploaded by

tharunreddy7776
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

stack

Stack question class 12 practice

Uploaded by

tharunreddy7776
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Write a program in Python, with separate user defined functions to perform the
following operations on Stack 'City'.
(a) - Push the pin code and name of the city in the stack 'City'
(b) - Display the latest added element in the stack 'City'
2. Priyanka has created a dictionary 'emeployee_data' containing EmpCode and
Salary as key value pairs for 5 Employees of Cyber Intratech. Write a program,
With separate user defined function, as mentioned below, to perform the
following operations:
(a) push_emp(): Push all those EmpCode, where the Salary is less than 25000, from
the dictionary into a stack 'stk_emp'
(b) pop_emp(): Remove all the elements from the stack, one at a time, in a Last-In-
First-Out(LIFO) manner and displays them. It also displays 'Stack is empty' once all
the element have been removed.
For Example:
If the sample content of the dictionary is as follows:
{'E001':15000,'E002':27000,'E003':30000,'E004':15000,'E005':19000}, then the
stack 'stk_emp' will contain EmpCode E001, E004, E005 after push_emp().
pop_emp() will pop and display employee record in LIFO fashion and display 'Stack is
empty' at last.
3. A school stores records of Class XII students using a list that contains multiple
lists as its elements. The structure of each such element is [Student_Name,
Marks, MainSubject]. Crate user-defined functions to perform the operations as
mentioned below:
(a) Push_student(): To push the Student_Name and Marks of all those students, who
have Science as MainSubject, into a Stack StudentInfo
(b) Pop_student(): To delete all items (one at a time) from the stack StudentInfo in
LIFO order and display them. Also display "Empty Stack" when there are no items
remaining in the stack.
For Example:
If the stored information is:
[['Akansha',98,"Mathematics"],["Priti",96,"Science"],["Garima",99,"Science"],
["Ayushi",78,"English"]]
The stack should contain:
["Garima",99]
["Priti",96]
The output should be:
["Garima",99]
["Priti",96]
Empty Stack
4. Consider a list named Nums which contains random integers.
Write the following user defined functions in Python and perform the specified
operations on a stack named BigNums.
(a) PushBig(): It checks every number from the list Nums and pushes all such
numbers which have 5 or more digits into the stack BigNums.
(b) PopBig(): It pops the numbers from the stack, BigNums and displays them. The
function should also display "Stack Empty" when there are no more numbers left in
the stack.
For example:
If the list Nums contains the following data:
Nums = [213, 10025, 167, 254923, 14, 1297653, 31498, 386, 92765]
Then on execution of PushBig(), the stack BigNums should store:
[10025, 254923, 1297653, 31498, 92765]
And on execution of PopBig(), the following output should be displayed:
92765
31498
1297653
254923
10025
Stack Empty
5. Write separate user defined functions for the following:
(a) PUSH(N) : This function accepts a list of names, N as parameter. It then pushes
only those names in the stack named OnlyA which contain the letter 'A'
(b) POPA(OnlyA) : This function pops each name from the stack OnlyA and displays
it. When the stack is empty, the message "EMPTY" is displayed.
For Example:
If the names in the list N are
['ANKITA','NITISH','ANWAR','DIPLE','HARKIRAT']
Then the stack OnlyA should store
['ANKITA','ANWAR','HARKIRAT']
And the output should be displayed as
HARKIRAT ANWAR ANKITA EMPTY
6. Consider the dictionary mobile:{model:[company, price]},write the following user
defined function
1) Push (mobile): add mobile model into the stack named as Cellphone, where
the mobile is manufactured by Samsung
2) Pop(): Pop each item and display if.If the stack is empty display Stack Empty
message
7. Consider the dictionary Movie:{m_name:[Language, director,collection]} write
the following user defined functions:
1. Push(): add moviename and director name into the stack named as Cinema
where its released in telgu
2. Pop(): Pop each item and display if.If the stack is empty display Stack Empty
message
8. Write the following user defined functions:
(a) pushEven(N) : This function accepts a list of integers named N as parameter.
It then pushes only even numbers into the stack named EVEN.
(b) popEven(EVEN) : This function pops each integer from the stack EVEN and
displays the popped value. When the stack is empty, the message "Stack Empty"
is displayed.
For Example:
If the list N contains
[10,5,3,8,15,4]
Then the stack, EVEN should store
[10,8,4]
And the output should be
4 8 10 Stack Empty
9. A list, NList contains following record as list elements:
[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the following
user defined functions in Pythons to perform the specified operations on the stack
named travel.
(a) Push_element(NList): It takes the nested list as an argument and pushes a list
object containing name of the city and country, which are not in India and distance is
less than 3500 km from Delhi.
(b) Pop_element(): It pops the objects from the stack and displays them. Also, the
function should display "Stack Empty: when there are no elements in the stack.
For example:
If the nested list contains the following data:
NList=[["New York", "USA",11734],["Naypyidaw","Myanmar", 3219],
["Dubai","UAE",2194],["London","England",6693],["Gangtok","India",1580],
["Columbo","Sri Lanka",3405]]
The stack should contain:
["Naypyidaw","Myanmar"]
["Dubai","UAE"]
["Columbo","Sri Lanka"]
The output should be:
["Columbo","Sri Lanka"]
["Dubai","UAE"]
["Naypyidaw","Myanmar"]
Stack Empty

You might also like