def connect(self, root):
    if (root and root.left and root.right):
        root.left.next = root.right
        root.right.next = (root.next and root.next.left)
        return (self.connect(root.left) or self.connect(root.right))
def connect(self, root):
    if (root and root.left and root.right):
        root.left.next = root.right
        root.right.next = (root.next and root.next.left)
        return (self.connect(root.left) or self.connect(root.right))