Example #1
0
    if temp1.value == temp2.value and match(temp1,temp2):
        return True
    else:
        return wrapper(temp1.left,temp2) or wrapper(temp1.right,temp2)



def subTree(temp1,temp2):
    if temp2 is None:
        return True
    return wrapper(temp1,temp2)




T1 = Basics.Tree()
T1.root = Basics.Node(1)
T1.addNode(2)
T1.addNode(3)
T1.addNode(4)
T1.addNode(5)
T1.addNode(6)
T1.addNode(7)
T1.addNode(8)
T1.addNode(9)
T1.addNode(10)
T1.addNode(11)
T1.addNode(12)
T1.addNode(13)
T1.addNode(14)
T1.addNode(15)
Example #2
0
            printutility(root.left)


def printpath(temp):
    print(temp.value)
    printutility(temp.left)
    printutility(temp.right)


def diameter(root):
    if root is None:
        return
    # temp =None
    ht = height(root)
    # path =[]
    printpath(temp)


T = Basics.Tree()
T.addNode(1)
T.addNode(2)
T.addNode(3)
T.addNode(4)
T.addNode(5)
T.root.left.left.right = Node(8)
T.root.left.left.right.left = Node(9)
T.root.left.right.left = Node(6)
T.root.left.right.right = Node(7)
temp = Node()
maximum = 0
diameter(T.root)
Example #3
0
from Tress import Basics as N


def addNodeBst(arr, start, end):
    if end < start:
        return None
    mid = (start + end) // 2
    temp = N.Node(arr[mid])
    temp.left = addNodeBst(arr, start, mid - 1)
    temp.right = addNodeBst(arr, mid + 1, end)
    return temp


T = N.Tree()
print(T.root)
arr = [1, 2, 3, 4, 5, 6, 7]
T.root = addNodeBst(arr, 0, len(arr) - 1)
print(T.root.value)
print("-" * 40)
T.inorder(T.root)