Construct a Maximum Binary Tree from two given Binary Trees | A binary tree node has data , pointer to left child and a pointer to right child ; Helper method that allocates a new node with the given data and None left and right pointers . ; Given a binary tree , print its nodes in inorder ; first recur on left child ; then print the data of node ; now recur on right child ; Method to find the maximum binary tree from two binary trees ; Driver Code ; First Binary Tree 3 / \ 2 6 / 20 ; Second Binary Tree 5 / \ 1 8 \ \ 2 8
class Node : NEW_LINE INDENT def __init__ ( self , data , left , right ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = left NEW_LINE self . right = right NEW_LINE DEDENT DEDENT def newNode ( data ) : NEW_LINE INDENT return Node ( data , None , None ) ; NEW_LINE DEDENT def inorder ( node ) : NEW_LINE INDENT if ( node == None ) : NEW_LINE INDENT return ; NEW_LINE DEDENT inorder ( node . left ) ; NEW_LINE print ( node . data , end = ' ▁ ' ) ; NEW_LINE inorder ( node . right ) ; NEW_LINE DEDENT def MaximumBinaryTree ( t1 , t2 ) : NEW_LINE INDENT if ( t1 == None ) : NEW_LINE INDENT return t2 ; NEW_LINE DEDENT if ( t2 == None ) : NEW_LINE INDENT return t1 ; NEW_LINE DEDENT t1 . data = max ( t1 . data , t2 . data ) ; NEW_LINE t1 . left = MaximumBinaryTree ( t1 . left , t2 . left ) ; NEW_LINE t1 . right = MaximumBinaryTree ( t1 . right , t2 . right ) ; NEW_LINE return t1 ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root1 = newNode ( 3 ) ; NEW_LINE root1 . left = newNode ( 2 ) ; NEW_LINE root1 . right = newNode ( 6 ) ; NEW_LINE root1 . left . left = newNode ( 20 ) ; NEW_LINE root2 = newNode ( 5 ) ; NEW_LINE root2 . left = newNode ( 1 ) ; NEW_LINE root2 . right = newNode ( 8 ) ; NEW_LINE root2 . left . right = newNode ( 2 ) ; NEW_LINE root2 . right . right = newNode ( 8 ) ; NEW_LINE root3 = MaximumBinaryTree ( root1 , root2 ) ; NEW_LINE inorder ( root3 ) ; NEW_LINE DEDENT