Skip to content

A Python implementation of a Doubly Linked List (DLL) data structure with basic operations such as insertion, deletion, searching, reversing, and traversal. Can be used as a standalone file or installed as a Python package.

License

Notifications You must be signed in to change notification settings

Ahmedhm1/DLL---Doubly-Linked-List-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doubly Linked List in Python

This project implements a Doubly Linked List (DLL) in Python with the following operations:

  • Insert values (at beginning, end, or specific index)
  • Remove values (from beginning, end, by index, or by value)
  • Change a node’s value at a given index
  • Reverse the list
  • Search for values
  • Get value at a specific index
  • String representation of the list

🐍 1. Basic Usage (easiest way)

If you just want to try the list without installing anything, copy doubly_linked_list.py into the same folder as your project and use:

from doubly_linked_list import DoublyLinkedList dll = DoublyLinkedList() dll.insert_at_end(10) dll.insert_at_end(20) dll.insert_at_beginning(5) print(dll) # Output: 5 <-> 10 <-> 20

📦 2. Advanced Usage (install as a package)

If you want to use this as a Python package, you first need Git installed.
👉 Download Git if you don’t already have it.

Then install directly from GitHub using pip:

pip install git+https://github.com/Ahmedhm1/DLL---Doubly-Linked-List-Python.git

Now you can import it anywhere:

from dll import DoublyLinkedList dll = DoublyLinkedList() dll.insert_at_end(100) dll.insert_at_end(200) dll.insert_at_end(300) print(dll) # Output: 100 <-> 200 <-> 300

🔎 Example Usage

from dll import DoublyLinkedList # Create list and insert values dll = DoublyLinkedList() dll.insert_at_end(10) dll.insert_at_end(20) dll.insert_at_beginning(5) dll.insert_at_index(15, 2) # Insert 15 at index 2 print(dll) # 5 <-> 10 <-> 15 <-> 20 # Remove values dll.remove_start() # Removes 5 dll.remove_end() # Removes 20 dll.remove_value(15) # Removes node with value 15 # Change a value dll.change_value(99, 0) # Change first element to 99 # Reverse the list dll.reverse() print(dll) # Search and get value print(dll.search(99)) # Get index of value print(dll.get_at_index(0)) # Get value at index 0

📂 Project Structure

Doubly-Linked-List/ │ ├── dll/ # Package source code │ ├── __init__.py # Exports DoublyLinkedList │ └── doubly_linked_list.py # DLL implementation │ ├── README.md ├── pyproject.toml # modern build file └── setup.py # Package setup script 

📖 Source Code

➡️ View doubly_linked_list.py directly if you just want to read the implementation.

About

A Python implementation of a Doubly Linked List (DLL) data structure with basic operations such as insertion, deletion, searching, reversing, and traversal. Can be used as a standalone file or installed as a Python package.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages