Find minimum and maximum elements in singly Circular Linked List | structure for a node ; Function to print minimum and maximum nodes of the circular linked list ; check list is empty ; initialize head to current pointer ; initialize max int value to min initialize min int value to max ; While last node is not reached ; If current node data is lesser for min then replace it ; If current node data is greater for max then replace it ; Function to insert a node at the end of a Circular linked list ; Create a new node ; check node is created or not ; insert data into newly created node ; check list is empty if not have any node then make first node it ; if list have already some node ; move firt node to last node ; put first or head node address in new node link ; put new node address into last node link ( next ) ; Function to print the Circular linked list ; if list is empty simply show message ; traverse first to last node ; Driver Code
class Node : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . data = 0 NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def printMinMax ( head ) : NEW_LINE INDENT if ( head == None ) : NEW_LINE INDENT return ; NEW_LINE DEDENT current = head ; NEW_LINE min = 1000000000 NEW_LINE max = - 1000000000 ; NEW_LINE while True : NEW_LINE INDENT if ( current . data < min ) : NEW_LINE INDENT min = current . data ; NEW_LINE DEDENT if ( current . data > max ) : NEW_LINE INDENT max = current . data ; NEW_LINE DEDENT current = current . next ; NEW_LINE if ( current == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ' Minimum ▁ = ▁ { } , ▁ Maximum ▁ = ▁ { } ' . format ( min , max ) ) NEW_LINE DEDENT def insertNode ( head , data ) : NEW_LINE INDENT current = head ; NEW_LINE newNode = Node ( ) NEW_LINE if not newNode : NEW_LINE INDENT print ( " Memory Error " ) ; NEW_LINE return head NEW_LINE DEDENT newNode . data = data ; NEW_LINE if ( head == None ) : NEW_LINE INDENT newNode . next = newNode ; NEW_LINE head = newNode ; NEW_LINE return head NEW_LINE DEDENT else : NEW_LINE INDENT while ( current . next != head ) : NEW_LINE INDENT current = current . next ; NEW_LINE DEDENT newNode . next = head ; NEW_LINE current . next = newNode ; NEW_LINE DEDENT return head NEW_LINE DEDENT def displayList ( head ) : NEW_LINE INDENT current = head ; NEW_LINE if ( head == None ) : NEW_LINE INDENT print ( " Display List is empty " ) ; NEW_LINE return ; NEW_LINE DEDENT else : NEW_LINE INDENT while True : NEW_LINE INDENT print ( current . data , end = ' ▁ ' ) ; NEW_LINE current = current . next ; NEW_LINE if ( current == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT Head = None ; NEW_LINE Head = insertNode ( Head , 99 ) ; NEW_LINE Head = insertNode ( Head , 11 ) ; NEW_LINE Head = insertNode ( Head , 22 ) ; NEW_LINE Head = insertNode ( Head , 33 ) ; NEW_LINE Head = insertNode ( Head , 44 ) ; NEW_LINE Head = insertNode ( Head , 55 ) ; NEW_LINE Head = insertNode ( Head , 66 ) ; NEW_LINE print ( " Initial ▁ List : ▁ " , end = ' ' ) NEW_LINE displayList ( Head ) ; NEW_LINE printMinMax ( Head ) ; NEW_LINE DEDENT