This Python program provides a command-line interface to manage a singly linked list. It supports various operations including insertion, deletion, and searching for elements. The list is managed using a set of methods that allow manipulation at the beginning, end, and random positions within the list.
- Insert elements at the beginning, end, or random position in the linked list.
- Delete elements from the beginning, end, or a random position in the linked list.
- Search for elements in the linked list.
- Display the entire linked list.
- Python 3.x
colorama
package for colored terminal output
-
Clone the repository:
git clone https://github.com/nishuR31/Linked_list.git cd Linked_list
python -m venv venv
python -m ensurepip
On Windows:
venv\Scripts\activate
On macOS/Linux:
source venv/bin/activate
pip install -r requirements.txt
or
pip intall colorama
python ll.py
or
python -u "ll.py"
1: Insert at the beginning 2: Insert at the end 3: Insert at a random position 4: Delete from the beginning 5: Delete from the end 6: Delete from a random position 7: Display the linked list 8: Search for an element 0: Exit
- Code Overview
node Class
Represents an individual node in the linked list with attributes for storing data and a reference to the next node.
linkedList Class
Contains methods for managing the linked list:
display()
: Displays all elements in the list.
insertFirst()
: Inserts an element at the beginning.
insertLast()
: Inserts an element at the end.
insertRandom()
: Inserts an element at a random position.
delFirst()
: Deletes the first element.
delLast()
: Deletes the last element.
delRandom()
: Deletes an element at a random position.
search()
: Searches for an element in the list.
menu()
: Function
Provides a command-line interface to interact with the linked list.
Example
1: Insert at beginning
2: Insert at end
3: Insert at random
4: Delete from start
5: Delete from last
6: Delete randomly
7: Display
8: Search
0: Exit
Enter your choice=> 7
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to contribute by opening issues or pull requests.
For any questions or collaborations, please reach out to me at:
- Email: [email protected]
- GitHub: nishuR31