0% found this document useful (0 votes)
9 views2 pages

Python Stack Implementation Questions

Uploaded by

pradhan.swag2008
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
0% found this document useful (0 votes)
9 views2 pages

Python Stack Implementation Questions

Uploaded by

pradhan.swag2008
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

DAV PUBLIC SCHOOL , MCL , JA , DERA

STACK QUESTIONS
Q1. Write a program in Python using function push(), pop(), and display() to
implement the stack .The program store the student details i.e. roll number , name
and average .

Q2. Write a program in Python to store the name of books using push() , pop()
and display() function to implement the stack.

Q3. WAF in Python PUSH(Arr) , where Arr is a list of numbers. from this list
push all numbers divisible by 5 into a stack implemented using a list . Display
the stack if it has at least one element otherwise display appropriate error
message .

Q4. Write a program to push and display the element to a Stack containing
characters.

Q5. A linear stack called Employee contains the following information :


- Phone number
- Name of Employee
Write the following functions to perform given operation:
(i) Push() - To push an object contacting phone number and Name of
Employee .
(ii) Display() - To display the data from the stack .

Q6. Write a program using user defined function to push a string to a stack , pop
every characters in reverse order from the stack and display .
.

Q7. Write a program to push elements into a stack of list, taking only numbers
from a source list with numbers and mathematical operators. While creating the
stack the elements in the source list will no more exit after the operation. Pop the
elements from newly created stack and display. Use user defined function. [3]
Example : Source list : M=[14, 19, ’+’, ’–‘, 20 , ‘*’, ‘/’, 11] Newly created stack
: N=[ 11, 20, 19, 14 ] Source list after execution : [’+’, ’–‘,‘*’, ‘/’ ]
Q8. 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.
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 22 98 56 34 12

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

Q10. Write a program to create a stack with the following functions to perform
given
operation:
(i) Push() - To push the numbers into stack .
(ii) Pop() - To pop the numbers from the stack and release the memory .
(iii) Display() - To display the status of stack after push and pop operation .

Q11. A string containing alphanumeric elements. Write a program using user


defined function to push the numbers to a stack of list. When all numbers push
into stack, pop every element and display.

Example:
S= “ Prasant born in the year 1971 his height is 145cm at the age of 27 he own a
car”
Element in stack : [7,2,5,4,1,1,7,9,1]

SOLVE ALL TYPE-C QUESTIONS RELATED TO


STACK FROM THE CHAPTER DATA STRUCTURE – II

You might also like