Exemplo n.º 1
0
def test1():
    # put 15 elements on RBT
    newTree = RBT()
    n = 30
    used = []
    while (len(used) < n + 1):
        rand = random.randint(0, n)
        if rand not in used:
            z = Node(rand)
            newTree.insert(z)
            used.append(rand)

    newTree.checkTreePointers(newTree.root)
    newTree.printTree(newTree.root, 0)
    print("done printing")
Exemplo n.º 2
0
def test2():
    # test the cases for the tree from p.317
    newTree = RBT()

    nums = [11, 2, 14, 1, 7, 15, 5, 8, 4]
    colors = ["B", "R", "B", "B", "B", "R", "R", "R", "R"]
    for i in nums:
        z = Node(nums[i])
        z.c = colors[i]
        newTree.insert(z)

    newTree.printTree(newTree.root, 0)

    newTree.checkTreePointers(newTree.root)
    newTree.checkTreeProperties(newTree.root)
    print("done printing")