Learn Programming and technology with ease @ developerpublish.com

HomePythonPython Program to Find the Largest Element in a Doubly Linked List

# Python Program to Find the Largest Element in a Doubly Linked List

In this Python program, weâ€™ll tackle the task of finding the largest element within a Doubly Linked List. Doubly Linked Lists are versatile data structures, and by solving this problem, you can enhance your understanding of working with them.

## Problem Statement

Given a Doubly Linked List, the goal is to find and output the largest element present in it.

## Python Program to Find the Largest Element in a Doubly Linked List

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

def __init__(self):

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

def find_largest_element(self):
return None
largest = current.data
while current:
if current.data > largest:
largest = current.data
current = current.next
return largest

# Example usage
if __name__ == "__main__":
elements = [12, 45, 7, 23, 56, 34]
for element in elements:
dll.insert(element)

largest = dll.find_largest_element()
print("Largest element:", largest)

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