2 - Linked List
2 - Linked List
A singly linked list is a linear collection of nodes, where each node contains a data
element and a reference (or pointer) to the next node in the sequence. The list starts
from a head node and terminates with a NULL or None pointer. Traversal in a singly
linked list is only possible in the forward direction.
class Node:
self.data = data
A circular linked list is similar to a singly linked list, but the last node points back to
the first node, creating a loop or circle. This means there is no NULL or None pointer
at the end; instead, the last node's pointer points back to the head of the list.
A doubly linked list is a type of linked list where each node contains a data element
and two references (or pointers): one to the next node in the sequence and another
to the previous node. This allows traversal in both forward and backward directions.
class Node:
self.data = data
A singly circular doubly linked list combines the properties of a circular linked list
with those of a doubly linked list. Each node has a reference to the next node and the
previous node, and the last node's next pointer points back to the first node, forming
a circular structure. This enables traversal in both directions while allowing the list to
wrap around in a circle.
class Node:
self.data = data
self.next = None
class SinglyCircularLinkedList:
if not head:
return
temp = head
while True:
temp = temp.next
if temp == head:
break
This code provides a basic framework for a singly circular doubly linked list, allowing
insertion at the end and displaying the list's elements.