Python program to find the maximum and minimum value node from a circular linked list

When it is required to find the maximum and minimum node values from a circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list.

In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node.

Another class needs to be created that would have an initialization function, and the head of the node would be initialized to 'None'. 

Multiple methods are defined by the user to add node to the linked list, to find the minimum and maximum values in the nodes and display them.

Below is a demonstration for the same −


Live Demo

class Node:  
   def __init__(self,data): = data = None  
class list_creation:  
   def __init__(self):  
      self.head = Node(None)  
      self.tail = Node(None) = self.tail = self.head  

   def add_data(self,my_data):  
      new_node = Node(my_data)  
      if is None:  
         self.head = new_node  
         self.tail = new_node   = self.head  
      else:   = new_node  
         self.tail = new_node   = self.head  

   def find_min_node(self):  
      curr = self.head;  
      min_val =;  
      if(self.head == None):  
         print("The list is empty");  
            if(min_val >  
               min_val =;  
            if(curr == self.head):  
      print("Minimum value node in the list: "+ str(min_val));  
   def find_max_node(self):  
      curr = self.head;  
      max_val =;  
      if(self.head == None):  
         print("List is empty");  
            if(max_val <  
               max_val =;  
            if(curr == self.head):  
      print("The maximum valueed node is : "+ str(max_val));
class circular_linked_list:  
   my_cl = list_creation()
   print("Values have been added to the list")


Values have been added to the list
The maximum valueed node is : 74
Minimum value node in the list: 11


  • The 'Node' class is created.
  • Another class with required attributes is created.
  • Another method named 'add_data' is defined, that is used to add data to the circular linked list.
  • Another method named 'find_max_node' is defined, that iterates through the list and gets the maximum value in a node.
  • Another method named 'find_min_node' is defined, that iterates through the list and gets the minimum value in a node.
  • An object of the 'list_creation' class is created, and the methods are called on it to add data.
  • An 'init' method is defined, that the first and last nodes of the circular linked list to None.
  • The 'find_max_node' method and the 'find_min_node' methods are called.
  • It iterates through the nodes in the linked list, gets the maximum and the minimum value in the list.
  • This is displayed on the console.