Stack
Stack
Stack
PRACTICE QUESTIONS
THEORY QUESTIONS
1. What are Data structures?
2. List out the various types of Data structure.
3. Differentiate between primitive and non-primitive data structres.
4. Define Stack.
5. Write the applications of stack.
6. Differentiate between Push and Pop operations in the context of
stacks.
7. At what situation Underflow occurs in Stack?
8. Is Overflow possible in Python in the context of stack?
9. What is meant by peek operation?
def pop_data():
if ==0: #statement5
print("Empty Stack,Cant pop")
return -1
else:
pop_item=Stack[-1]
Stack. #statement6
return pop_item
Stack= # statement1
push_data ([20,11,30,15,2])
print(pop_data())
1. Identify the missing code in statement 1.
2. Identify the missing code in statement 2 for completing
the stop parameter in the for loop.
3. Identify the missing function in statement 3 for inserting
Data into the stack.
4. What will be the contents of stack which will be printed
in statement 4?
5. Identify the missing code in statement 5 in
pop_data() function.
6. Identify the missing code in statement 6 for popping the
element in the stack.
3- MARKS
1. Write a function in Python PUSH(Arr), where Arr is a list of
numbers. From this list push all numbers divisible by 5 into a
stack implemented by using a list. Display the stack if it has at
least one element, otherwise display appropriate error message.
2. Write a function in Python POP(Arr), where Arr is a stack
implemented by a list of numbers. The function returns the value
deleted from the stack.
3. 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
4. Jiya has a list containing 8 integers. You need to help her create
a program with two user defined functions to perform the
following operations based on this list.
• Traverse the content of the list and push those numbers
into a stack which is divisible by both 5 and 3.
• Pop and display the content of the stack.
For example: If the sample Content of the list is as follows:
L=[5,15,21,30,45,50,60,75] Sample Output of the code should
be: 75 60 45 30 15
5. Varun has a list containing 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 2 digit
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=[2, 131, 34, 56, 21, 379, 98, -22, 35, 38]
Sample Output of the code should be:
38 35 -22 98 21 56 34
6. Write the definition of a function POP_PUSH(LPop, LPush, N) in
Python.
The function should Pop out the last N elements of the list LPop
and Push them into the list LPush.
For example :
If the contents of the list LPop are [10, 15, 20, 30]
And value of N passed is 2,
then the function should create the list LPush as [30,20] And the
list LPop should now contain [10, 15]
For example:
If the dictionary Stu_dict contains the following data:
Stu_dict ={5:(87,68,89), 10:(57,54,61), 12:(71,67,90),
14:(66,81,80), 18:(80,48,91)}
After executing Push_elements(), Stk_ID should contain
[5,12,14,18]
After executing Pop_elements(), The output should be:
18
14
12
5
Stack Empty
*********************************************************************