Special two digit numbers in a Binary Search Tree | A Tree node ; Function to create a new node ; If the tree is empty , return a new node ; If key is smaller than root 's key,  go to left subtree and set successor  as current node ; return the ( unchanged ) node pointer ; Function to find if number is special or not ; sum_of_digits , prod_of_digits Check if number is two digit or not ; Function to count number of special two digit number ; Driver code ; Function call , to check each node for special two digit number
class Node : NEW_LINE INDENT def __init__ ( self , x ) : NEW_LINE INDENT self . data = x NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def insert ( node , data ) : NEW_LINE INDENT global succ NEW_LINE root = node NEW_LINE if ( node == None ) : NEW_LINE INDENT return Node ( data ) NEW_LINE DEDENT if ( data < node . data ) : NEW_LINE INDENT root . left = insert ( node . left , data ) NEW_LINE DEDENT elif ( data > node . data ) : NEW_LINE INDENT root . right = insert ( node . right , data ) NEW_LINE DEDENT return root NEW_LINE DEDENT def check ( num ) : NEW_LINE INDENT sum = 0 NEW_LINE i = num NEW_LINE if ( num < 10 or num > 99 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT sum_of_digits = ( i % 10 ) + ( i // 10 ) NEW_LINE prod_of_digits = ( i % 10 ) * ( i // 10 ) NEW_LINE sum = sum_of_digits + prod_of_digits NEW_LINE DEDENT if ( sum == num ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def countSpecialDigit ( rt ) : NEW_LINE INDENT global c NEW_LINE if ( rt == None ) : NEW_LINE INDENT return NEW_LINE DEDENT else : NEW_LINE INDENT x = check ( rt . data ) NEW_LINE if ( x == 1 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT countSpecialDigit ( rt . left ) NEW_LINE countSpecialDigit ( rt . right ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = None NEW_LINE c = 0 NEW_LINE root = insert ( root , 50 ) NEW_LINE root = insert ( root , 29 ) NEW_LINE root = insert ( root , 59 ) NEW_LINE root = insert ( root , 19 ) NEW_LINE root = insert ( root , 53 ) NEW_LINE root = insert ( root , 556 ) NEW_LINE root = insert ( root , 56 ) NEW_LINE root = insert ( root , 94 ) NEW_LINE root = insert ( root , 13 ) NEW_LINE countSpecialDigit ( root ) NEW_LINE print ( c ) NEW_LINE DEDENT