Point arbit pointer to greatest value right side node in a linked list | Node class ; This function populates arbit pointer in every node to the greatest value to its right . ; using static maxNode to keep track of maximum orbit node address on right side ; if head is null simply return the list ; if head . next is null it means we reached at the last node just update the max and maxNode ; Calling the populateArbit to the next node ; updating the arbit node of the current node with the maximum value on the right side ; if current Node value id greater then the previous right node then update it ; Utility function to prresult linked list ; Driver code
class newNode : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE self . arbit = None NEW_LINE DEDENT DEDENT maxNode = newNode ( None ) NEW_LINE def populateArbit ( head ) : NEW_LINE INDENT global maxNode NEW_LINE if ( head == None ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( head . next == None ) : NEW_LINE INDENT maxNode = head NEW_LINE return NEW_LINE DEDENT populateArbit ( head . next ) NEW_LINE head . arbit = maxNode NEW_LINE if ( head . data > maxNode . data and maxNode . data != None ) : NEW_LINE INDENT maxNode = head NEW_LINE DEDENT return NEW_LINE DEDENT def printNextArbitPointers ( node ) : NEW_LINE INDENT print ( " Node TABSYMBOL Next ▁ Pointer TABSYMBOL Arbit ▁ Pointer " ) NEW_LINE while ( node != None ) : NEW_LINE INDENT print ( node . data , " TABSYMBOL TABSYMBOL " , end = " " ) NEW_LINE if ( node . next ) : NEW_LINE INDENT print ( node . next . data , " TABSYMBOL TABSYMBOL " , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NULL " , " TABSYMBOL TABSYMBOL " , end = " " ) NEW_LINE DEDENT if ( node . arbit ) : NEW_LINE INDENT print ( node . arbit . data , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NULL " , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE node = node . next NEW_LINE DEDENT DEDENT head = newNode ( 5 ) NEW_LINE head . next = newNode ( 10 ) NEW_LINE head . next . next = newNode ( 2 ) NEW_LINE head . next . next . next = newNode ( 3 ) NEW_LINE populateArbit ( head ) NEW_LINE print ( " Resultant ▁ Linked ▁ List ▁ is : " ) NEW_LINE printNextArbitPointers ( head ) NEW_LINE