Learn Programming and technology with ease @ developerpublish.com

HomePythonPython Program to Convert Singly Linked List to Circular List

# Python Program to Convert Singly Linked List to Circular List

A circular linked list is a variation of the linked list data structure where the last nodeâ€™s â€˜nextâ€™ pointer points back to the first node, forming a loop. This python program demonstrates how to convert a singly linked list into a circular linked list.

## Problem Statement

Given a singly linked list, your goal is to convert it into a circular linked list by making the last nodeâ€™s â€˜nextâ€™ pointer point back to the first node.

## Python Program to Convert Singly Linked List to Circular List

```class Node:
def __init__(self, data):
self.data = data
self.next = None

def __init__(self):

def append(self, data):
new_node = Node(data)
else:
while current.next:
current = current.next
current.next = new_node

def convert_to_circular(self):
return
while current.next:
current = current.next

def display(self):
print("List is empty")
return
while True:
print(current.data, end=" -> ")
current = current.next
break
print("...")

# Input: Creating a linked list
elements = [1, 2, 3, 4, 5]
for element in elements:

```

## Input / Output

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...