Thursday, December 4, 2025

DSA Assignment-11: Stack Implementation by extending Singly Linked List

Follow me 



Assignment - 9

Assignment - 10


Implementation of Stack data structure in Python using Singly Linked List with methods like push, pop, peek, size, and is_empty in an inherited class.


Task 1: Import Singly Linked List Module

Import the module containing Singly Linked List (SLL) code into your Python file.

Task 2: Create Stack Class

Define a class Stack that inherits from SLL class.

Task 3: is_empty() Method

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

Task 4: push() Method

Define push() method in Stack class to add data onto the stack.

Task 5: pop() Method

Define pop() method in Stack class to remove the top element from the stack.

Task 6: peek() Method

Define peek() method to return the top element of the stack without removing it.

Task 7: size() Method

Define size() method to return the number of elements present in the stack.


This assignment successfully demonstrates how to implement the Stack data structure by extending the Singly Linked List class in Python. The stack operations such as push, pop, peek, size, and is_empty are performed efficiently using linked list concepts, ensuring proper use of inheritance and dynamic memory handling.

No comments:

Post a Comment

DSA Assignment-11: Stack Implementation by extending Singly Linked List

Follow me   Assignment - 9 Assignment - 10 Implementation of Stack data structure in Python using Singly Linked List with methods like push,...