linked list
in this Lecture, we will learn about the implementation of a linked list
in Python. To implement the linked list in Python, we will use classes in
Python. we know that a linked list consists of nodes and nodes have two
elements i.e. data and a reference to another node. Let’s implement the node
first.
What is Linked List in Python
A linked list is a type of linear data structure similar to arrays. It is a collection
of nodes that are linked with each other. A node contains two things first is
data and second is a link that connects it with another node. Below is an
example of a linked list with four nodes and each node contains character data
and a link to another node. Our first node is where head points and we can
access all the elements of the linked list using the head.
Creating a linked list in Python
In this LinkedList class, we will use the Node class to create a linked list. In this
class, we have an __init__ method that initializes the linked list with an empty
head. Next, we have created an insertAtBegin() method to insert a node at the
beginning of the linked list, an insertAtIndex() method to insert a node at the
given index of the linked list, and insertAtEnd() method inserts a node at the
end of the linked list. After that, we have the remove_node() method which
takes the data as an argument to delete that node. In
the remove_node() method we traverse the linked list if a node is present
equal to data then we delete that node from the linked list. Then we have
the sizeOfLL() method to get the current size of the linked list and the last