Function to merge given two binary trees
def MergeTrees ( t1 , t2 ) : NEW_LINE INDENT if ( not t1 ) : NEW_LINE INDENT return t2 ; NEW_LINE DEDENT if ( not t2 ) : NEW_LINE INDENT return t1 ; NEW_LINE DEDENT s = [ ] NEW_LINE temp = snode ( t1 , t2 ) NEW_LINE s . append ( temp ) ; NEW_LINE n = None NEW_LINE while ( len ( s ) != 0 ) : NEW_LINE INDENT n = s [ - 1 ] NEW_LINE s . pop ( ) ; NEW_LINE if ( n . l == None or n . r == None ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT n . l . data += n . r . data ; NEW_LINE if ( n . l . left == None ) : NEW_LINE INDENT n . l . left = n . r . left ; NEW_LINE DEDENT else : NEW_LINE INDENT t = snode ( n . l . left , n . r . left ) NEW_LINE s . append ( t ) ; NEW_LINE DEDENT if ( n . l . right == None ) : NEW_LINE INDENT n . l . right = n . r . right ; NEW_LINE DEDENT else : NEW_LINE INDENT t = snode ( n . l . right , n . r . right ) NEW_LINE s . append ( t ) ; NEW_LINE DEDENT DEDENT return t1 ; NEW_LINE DEDENT