Wednesday, August 13, 2025

DSA using Python: Assignment-4: Doubly Linked List



In this assignment, we implement a Doubly Linked List (DLL) using Python.  

A DLL is a data structure where each node contains:

- **data** (the value)

- **next** pointer (link to next node)

- **prev** pointer (link to previous node)


It allows traversal in both directions, making insertion and deletion more flexible than a singly linked list.



Assignment-4: Doubly Linked List


### ✅ Task 1: Define Node class

1. Define a class Node to describe a node of a doubly linked list.


### ✅ Task 2: Define DLL class

2. Define a class DLL to implement Doubly Linked List with __init__() method to create and initialise start reference variable.


### ✅ Task 3: is_empty()

3. Define a method is empty() to check if the linked list is empty in DLL class.


### ✅ Task 4: insert_at_start()

4. In class DLL, define a method insert_at_start() to insert an element at the starting of the list.


### ✅ Task 5: insert_at_last()

5. In class DLL, define a method insert_at_last() to insert an element at the end of the list.


### ✅ Task 6: search()

6. In class DLL, define a method search() to find the node with specified element value.


### ✅ Task 7: insert_after()

7. In class DLL, define a method insert_after() to insert a new node after a given node of the list.


### ✅ Task 8: print_all()

8. In class DLL, define a method to print all the elements of the list.


### ✅ Task 9: Iterator

9. In class DLL, implement iterator for DLL to access all the elements of the list in a sequence.


### ✅ Task 10: delete_first()

10. In class DLL, define a method delete_first() to delete first element from the list. 


### ✅ Task 11: delete_last()

11. In class DLL, define a method delete_last() to delete last element from the list.


### ✅ Task 12: delete_item()

12. In class DLL, define a method delete_item() to delete specified element from the list.


A Doubly Linked List gives more flexibility compared to a Singly Linked List as we can traverse in both directions.  

This assignment builds understanding of bidirectional linking and efficient insertion/deletion operations.


No comments:

Post a Comment

Recursion in DSA using Python

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