<qiyuangong>099_Recover_Binary_Search_Tree_1.py
def recoverTree( root):
    pre = first = second = None
    while root is not None:
        if root.left is not None:
            temp = root.left
            while temp.right is not None and temp.right != root:
                temp = temp.right
            if temp.right is not None:
                if pre is not None and pre.val > root.val:
                    if first is None:
                        first = pre
                    second = root
                pre = root
                temp.right = None
                root = root.right
            else:
                temp.right = root
                root = root.left
        else:
            if pre is not None and pre.val > root.val:
                if first is None:
                    first = pre
                second = root
            pre = root
            root = root.right
    
    if first is not None and second is not None:
        first.val, second.val = second.val, first.val
def sample_funcname ( var_0 ) :
    var_4 = var_1 = var_2 = None
    while var_0 is not None :
        if var_0.left is not None :
            var_6 = var_0.left
            while var_6.right is not None and var_6.right != var_0 :
                var_6 = var_6.right
            if var_6.right is not None :
                if var_4 is not None and var_4.val > var_0.val :
                    if var_1 is None :
                        var_1 = var_4
                    var_2 = var_0
                var_4 = var_0
                var_6.right = None
                var_0 = var_0.right
            else :
                var_6.right = var_0
                var_0 = var_0.left
        else :
            if var_4 is not None and var_4.val > var_0.val :
                if var_1 is None :
                    var_1 = var_4
                var_2 = var_0
            var_4 = var_0
            var_0 = var_0.right
    if var_1 is not None and var_2 is not None :
        var_1.val , var_2.val = var_2.val , var_1.val
