Linked List
Practice Questions
Implement Linked List in Python
Implementation of linked list in python
We implement the concept of linked lists using the list in Python.
We create a Node class and create another class to use this node object. We pass the appropriate values through the node object to point to the next data elements. The below program creates the linked list with three data elements. In the next section we will see how to traverse the linked list.
class Node:
def __init__(self, dataval=None):
self.dataval = dataval
self.nextval = None
class SLinkedList:
def __init__(self):
self.headval = None
list1 = SLinkedList()
list1.headval = Node("Mon")
e2 = Node("Tue")
e3 = Node("Wed")
# Link 1st Node to second node
list1.headval.nextval = e2
# Link 2nd Node to third node
e2.nextval = e3