Let us check the values of nextRight pointers
print ( " Following are populated nextRight pointers in " " the tree ( - 1 is printed if there is no nextRight ) " ) NEW_LINE if ( root . nextRight != None ) : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . data , root . nextRight . data ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . data , - 1 ) ) NEW_LINE DEDENT if ( root . left . nextRight != None ) : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . left . data , root . left . nextRight . data ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . left . data , - 1 ) ) NEW_LINE DEDENT if ( root . right . nextRight != None ) : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . right . data , root . right . nextRight . data ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . right . data , - 1 ) ) NEW_LINE DEDENT if ( root . left . left . nextRight != None ) : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . left . left . data , root . left . left . nextRight . data ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . left . left . data , - 1 ) ) NEW_LINE DEDENT if ( root . right . right . nextRight != None ) : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . right . right . data , root . right . right . nextRight . data ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " nextRight of % d is % d " % ( root . right . right . data , - 1 ) ) NEW_LINE DEDENT print ( ) NEW_LINE if __name__ == " _ _ main _ _ " : NEW_LINE main ( ) NEW_LINE