Thursday, October 23, 2025

DSA using Python: Assignment-7: Stack using list

Stack Using List


This assignment is for practice, focusing on implementing a Stack using Python lists. It covers key stack operations like push, pop, peek, is_empty, and size, following the LIFO principle. This helps in understanding stack behavior and list-based implementation in Python.

Assignment-7: Stack using list


Task 1: Define Stack class with init()
Define a class Stack to implement stack data structure using list. Define __init__() method to create an empty list object as instance object member of Stack.

Task 2: Define is_empty() method
Define a method is_empty() to check if the stack is empty in Stack class.

Task 3: Define push() method
In Stack class, define push() method to add data onto the stack.

Task 4: Define pop() method
In Stack class, define pop() method to remove top element from the stack.

Task 5: Define peek() method
In Stack class, define peek() method to return top element on the stack.

Task 6: Define size() method
In Stack class, define size() method to return size of the stack that is number of items present in the stack.

No comments:

Post a Comment

DSA using Python: Priority Queue

Follow me If you want to understand with  Graphical Representation   click on it. You can find the explanatory video at the bottom of this p...