Showing posts with label Data Structures. Show all posts
Showing posts with label Data Structures. 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.

Monday, November 24, 2025

DSA Using Python – Assignment 9: Stack Implementation with Programs

Stack using Linked List Concept


This assignment is designed for practicing Stack implementation in Python using the Singly Linked List concept. It helps students learn stack operations like push(), pop(), peek(), is_empty(), and size() with simple examples and Python code. This task improves your understanding of pointers, nodes, memory handling, and DSA concepts used in real programming.



Assignment 7 – Stack Basics in Python

Assignment 8 – Stack Operations in Python


Assignment-9: Stack using Linked List Concept

🧩 Task 1: Create Stack Class

Define a class Stack to implement stack data structure using singly linked list concept.
Define an __init__() method to initialize start reference variable and item_count variable to keep track of number of elements in the stack.

🧩 Task 2: Check if Stack is Empty

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

🧩 Task 3: Add Element to Stack

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

🧩 Task 4: Remove Top Element

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

🧩 Task 5: View Top Element

In Stack class, define peek() method to return the top element of the stack.

🧩 Task 6: Find Stack Size

In Stack class, define size() method to return the size of the stack, i.e., number of items present in the stack.



Continue Learning:

More DSA assignments and Python projects coming soon!

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