0% found this document useful (0 votes)
4 views3 pages

2 - Linked List

The document describes various types of linked lists, including singly linked lists, circular linked lists, doubly linked lists, and singly circular doubly linked lists. Each type has distinct properties regarding node connections and traversal directions. It also provides example Python code for implementing these linked lists and their basic operations.

Uploaded by

nitugp.1216
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

2 - Linked List

The document describes various types of linked lists, including singly linked lists, circular linked lists, doubly linked lists, and singly circular doubly linked lists. Each type has distinct properties regarding node connections and traversal directions. It also provides example Python code for implementing these linked lists and their basic operations.

Uploaded by

nitugp.1216
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Single 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.

Example of a Node in a Singly Linked List:

class Node:

def __init__(self, data):

self.data = data

self.next = None # Reference to the next node

Circular Linked List:

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.

Double Linked 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.

Example of a Node in a Doubly Linked List:

class Node:

def __init__(self, data):

self.data = data

self.next = None # Reference to the next node

self.prev = None # Reference to the previous node


Single Circular Doubly Linked List:

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.

Here's an example of a basic implementation of a singly circular doubly linked list in


Python, incorporating the Node structure and basic operations like insertion and
deletion:

class Node:

def __init__(self, data):

self.data = data

self.next = None

class SinglyCircularLinkedList:

# (Assuming nodes are already created and linked in a circular manner)

def traverse(self, head):

if not head:

return

temp = head

while True:

print(temp.data, end=" ")

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.

You might also like