Showing posts with label DSA Assignment. Show all posts
Showing posts with label DSA Assignment. Show all posts

Friday, November 28, 2025

DSA using Python: Assignment - 10: Stack using Linked List in Python

Follow me

Stack using Linked List diagram in Python DSA


Assignment - 8

Assignment - 9


In Data Structures using Python, stack is a linear data structure that follows LIFO (Last In First Out) order. Here, we will implement stack using Linked List concept with methods like push(), pop(), peek(), size() and is_empty(). This is also part of DSA Assignment 10 for Python students.


Task 1 – Import Linked List Module
  1. Import module containing singly linked list code in your python file.
Task 2 – Create Stack Class
  1. Define a class Stack to implement stack data structure. Define \_\_init\_\_() method to create Singly Linked List (SLL) object.
Task 3 – Check If Stack is Empty
  1. Define a method is\_empty() to check if the stack is empty in Stack class.
Task 4 – Add Element in Stack
  1. In Stack class, define push() method to add data onto the stack.
Task 5 – Remove Element from Stack
  1. In Stack class, define pop() method to remove top element from the stack.
Task 6 – Return Top Element
  1. In Stack class, define peek() method to return top element on the stack.
Task 7 – Return Stack Size
  1. In Stack class, define size() method to return size of the stack that is number of items present in the stack.

✔ Works on LIFO principle  
✔ Constant time complexity O(1) for push & pop  
✔ Best for dynamic stack implementation  


This was the complete implementation of Stack using Linked List in Python with all major operations. Students can use this code for their DSA Assignment 10 and improve Python skills.

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