Remove all the Even Digit Sum Nodes from a Circular Singly Linked List | Structure for a node ; Function to insert a node at the beginning of a Circular linked list ; Create a new node and make head as next of it . ; If linked list is not None then set the next of last node ; Find the node before head and update next of it . ; Point for the first node ; Function to deltete the node from a Circular Linked list ; If node to be delteted is head node ; Traverse list till not found deltete node ; Copy the address of the node ; Finally , free the memory occupied by delt ; Function to find the digit sum for a number ; Function to deltete all the Even Digit Sum Nodes from the singly circular linked list ; Traverse the list till the end ; If the node ' s ▁ data ▁ is ▁ Fibonacci , ▁ ▁ deltete ▁ node ▁ ' ptr ; Point to the next node ; Function to print nodes in a given Circular linked list ; Driver code ; Initialize lists as empty ; Created linked list will be 9.11 .34 .6 .13 .21
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def push ( head_ref , data ) : NEW_LINE INDENT ptr1 = Node ( data ) NEW_LINE temp = head_ref NEW_LINE ptr1 . data = data NEW_LINE ptr1 . next = head_ref NEW_LINE if ( head_ref != None ) : NEW_LINE INDENT while ( temp . next != head_ref ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = ptr1 NEW_LINE DEDENT else : NEW_LINE INDENT ptr1 . next = ptr1 NEW_LINE DEDENT head_ref = ptr1 NEW_LINE return head_ref NEW_LINE DEDENT def delteteNode ( head_ref , delt ) : NEW_LINE INDENT temp = head_ref NEW_LINE if ( head_ref == delt ) : NEW_LINE INDENT head_ref = delt . next NEW_LINE DEDENT while ( temp . next != delt ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = delt . next NEW_LINE del ( delt ) NEW_LINE return NEW_LINE DEDENT def digitSum ( num ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( num != 0 ) : NEW_LINE INDENT sum += ( num % 10 ) NEW_LINE num //= 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT def delteteEvenDigitSumNodes ( head ) : NEW_LINE INDENT ptr = head NEW_LINE next = None NEW_LINE while True : NEW_LINE INDENT if ( not ( digitSum ( ptr . data ) & 1 ) ) : NEW_LINE INDENT delteteNode ( head , ptr ) NEW_LINE DEDENT next = ptr . next NEW_LINE ptr = next NEW_LINE if ( ptr == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT def printList ( head ) : NEW_LINE INDENT temp = head NEW_LINE if ( head != None ) : NEW_LINE INDENT while True : NEW_LINE INDENT print ( temp . data , end = ' ▁ ' ) NEW_LINE temp = temp . next NEW_LINE if ( temp == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 21 ) NEW_LINE head = push ( head , 13 ) NEW_LINE head = push ( head , 6 ) NEW_LINE head = push ( head , 34 ) NEW_LINE head = push ( head , 11 ) NEW_LINE head = push ( head , 9 ) NEW_LINE delteteEvenDigitSumNodes ( head ) NEW_LINE printList ( head ) NEW_LINE DEDENT