PP Lab-Experiment
No.8 QUESTIONS
Registration No.: 241090064
Student Name: Sahil Vilas Desai
Class: SY BTech EXTC
Course Code: R5ET2005L
Course Name: Python Programing Lab
Python Programs on Stacks and Queues
Stacks
Question 1: WAP and create a Class named as Stacks and the Method named as Push, Pop,
Peek, isempty, size. Perform the operations:
1. Take an empty list add the below elements using the methods [1, 4, 2, 3, 5]
2. Sort the above list into ascending order using only methods.
Question 2: Write a Python program to implement a stack using a list, supporting the
following operations:
• push() → to insert an element into the stack
• pop() → to remove the top element
• display() → to show all elements in the stack
Question 3: Write a Python program to check whether the stack is empty or full using class
implementation.
Question 4: Write a Python program to display the top element (peek) of a stack without
removing it.
Question 5: Write a Python program to reverse a string using a stack (push each character
and then pop to get reversed output).
Queues
Question 1: WAP and create a Class named as Queue and the Method named as Enqueue,
Dequeue, Peek, isempty, size. Perform the operations:
1. Take an empty list add the below elements using the methods [1, 4, 2, 3, 5]
2. Sort the above list into ascending order using only methods.
Question 2: Write a Python program to implement a queue using a list, supporting the following
operations:
• enqueue() → to insert an element into the queue
• dequeue() → to remove an element from the front
• display() → to show all elements in the queue
Question 3: Write a Python program to check whether the queue is empty or full using a class
implementation.
Question 4: Write a Python program to find the front and rear elements of a queue without
deleting them.
Conclusion
In this experiment, we learned how to implement Stacks and Queues in Python
using classes and lists.
We performed operations such as push, pop, peek, enqueue, dequeue, isEmpty,
and size, and also practiced sorting, reversing, and checking the front and rear
elements.
This helped us understand how data structures manage data in LIFO (Stack) and
FIFO (Queue) order, improving our knowledge of algorithmic thinking and memory
handling in programming.