100% found this document useful (1 vote)
438 views4 pages

Important Questions On Stack

Class 12 stack important questions

Uploaded by

ram priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
438 views4 pages

Important Questions On Stack

Class 12 stack important questions

Uploaded by

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

Important Questions on Stack

for
Term 2 Examination
Class 12 Computer Science (CBSE)

If you want to give some donation then


My QR Code:

And UPI ID:


govind10788@okicici
Important Questions for Exams
Q1. Write a function push(),pop() and display() to add a new student name, remove a student name and to
display student names in stack format, according to Data Structure in Python.

st=[ ]
def push():
sn=input("Enter name of student:")
st.append(sn)
print(st)

def pop():
if st==[]:
print("Stack is empty")
else:
print("Deleted student name :",st.pop())

def display():
if st==[]:
print("Stack is empty")
else:
for i in st[::-1]:
print(i)

Q2. Write a function Push() which to add in a stack named "MyStack". After calling push() three times, a
message should be displayed "Stack is Full"

st=[ ]
StackSize=3
def push():
sn=input("Enter name of student:")
if len(st)<StackSize:
st.append(sn)
else:
print("Stack is full!")
print(st)
Q3: 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:
• Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
(marks) is greater than 75.
• Pop and display the content of the stack.

R={"OM":76, "JAI":45, "BOB":89,"ALI":65, "ANU":90, "TOM":82}

st=[]
def push():
for i in R:
if R[i]>75:
st.append(i)
print(st)

def pop():
while True:
if st!=[]:
print(st.pop(),end=" ")
else:
break

Q4: Alam has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the following operations based on this list.
• Traverse the content of the list and push the even numbers into a stack.
• Pop and display the content of the stack.

N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
st=[]
def push():
for i in N:
if i%2==0:
st.append(i)

def pop():
while True:
if st!=[]:
print(st.pop(),end=" ")
else:
break
Q 5: Write a function push(l) to perform push opration in stack. Where a list is given:
L=[10,12,15,16,17,18,20,21,25]
Push only those element who is divisible by 5.

def push(l):
L2.append(l)

L2=[]
L1=[10,12,15,16,17,18,20,21,25]
for i in L1:
if i%5==0:
push(i)

print("Original List:\n",L1)
print("List after using push:\n",L2)

Q 6: Write a function Addvowel(l) to perform push opration in stack. Where a list is given:

L=[‘Ansh’,’Vipin’,’Ishan’,’Devesh’,’Om’,’Upashna’]
Push only those element who is started from vowels

def Addvowel(l):
L2.append(l)

L2=[]
L1=['Ansh','Vipin','Ishan','Devesh','Om','Upashna']
for i in L1:
if i[0] in 'aeiouAEIOU':
Addvowel(i)

print("Original List:\n",L1)
print("List after using push:\n",L2)

You might also like