This Python code provides an implementation of a singly linked list and demonstrates various operations on it. A singly linked list is a linear data structure where elements are stored in a sequence, and each element points to the next element in the list.
The provided code includes the following features and operations for a singly linked list:
-
Node Class:
- The
Node
class represents a single node in the linked list. It contains data and a reference to the next node.
- The
-
Singly Linked List Class:
- The
LinkedList
class represents the singly linked list. It includes the following operations:- Insertion at the Beginning: Add an element to the beginning of the list.
- Insertion at the End: Add an element to the end of the list.
- Insertion at a Specific Index: Add an element at a specific index.
- Deletion from the Beginning: Remove the first element from the list.
- Deletion from the End: Remove the last element from the list.
- Deletion at a Specific Index: Remove an element at a specific index.
- Deletion by Value: Remove an element with a specific value.
- Updating an Element at a Specific Index: Modify an element at a specific index.
- Updating an Element by Value: Modify an element by its value.
- Printing the Linked List: Display the elements in the linked list.
- Returning Value at a Specific Index: Retrieve the value at a specific index.
- Returning Index of a Specific Value: Find the index of a specific value.
- Getting the Size of the Linked List: Calculate the number of elements in the list.
- The
You can use this code to create a singly linked list, insert elements, perform various operations, and retrieve information about the list.