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

XII Stack Worksheet

Uploaded by

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

XII Stack Worksheet

Uploaded by

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

Computer Science

Stack Worksheet

Name: ____________________ Class:

XII

1. How to create an empty stack?

2. How to add elements to a stack?

3. How to delete / remove elements from the stack

4. How to traverse or displaying elements of stack?

5. How to check for empty stack?

6. Expand the term LIFO.

7. What do you mean by Stack?

8. What is the difference between pop( ) and append( ) function of list?

9. What do you mean by data structure?

10. Write a code to create an empty stack named "st".

11. Write the technical term used for adding element in stack.

12. What happen when you try to delete an element from an empty stack?

13. Write a function push(student) and pop(student) to add a new

student name

and remove a student name from a list student, Considering them to

act as

PUSH and POP operations of stack Data Structure in Python.

1
14. Write a menu based program to add, delete and display the record of

hostel using list as stack data structure in python. Record of hostel

contains the fields: Hostel number, Total Students and Total Rooms.

15. Write a function push() to add the names one by one from a list of

names which has at least one vowel in it.

16. Define a function pushodd() to append only odd numbers from a list

of numbers passed one by one. And define function popodd() to delete

one by one.

17. 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”]

2
[“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

18. 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

3
Pen

Notebook

Watch

The output should be:

The count of elements in the stack is 3

19. A dictionary contains the names of some cities and their population in crore.

Write a python function push(stack, data), that accepts an empty list, which

is the stack and data, which is the dictionary and pushes the names of those

countries onto the stack whose population is greater than 25 crores.

For example :

The data is having the contents {'India':140, 'USA':50, 'Russia':25, 'Japan':10}

then the execution of the function push() should push India and USA on the

stack.

21. A list of numbers is used to populate the contents of a stack using a function

push(stack, data) where stack is an empty list and data is the list of numbers.

The function should push all the numbers that are even to the stack. Also

write the function pop() that removes the top element of the stack on its

each call.

4
5

You might also like