Do level order traversal until last node
while ( len ( q ) ) : NEW_LINE INDENT temp = q . pop ( 0 ) NEW_LINE if temp is d_node : NEW_LINE INDENT temp = None NEW_LINE return NEW_LINE DEDENT if temp . right : NEW_LINE INDENT if temp . right is d_node : NEW_LINE INDENT temp . right = None NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT q . append ( temp . right ) NEW_LINE DEDENT DEDENT if temp . left : NEW_LINE INDENT if temp . left is d_node : NEW_LINE INDENT temp . left = None NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT q . append ( temp . left ) NEW_LINE DEDENT DEDENT DEDENT