Пример #1
0
 def test_delete_notExist(self):
     arbol = BST()
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.delete(38)
Пример #2
0
def solve():
    map, reserved, separators, operands = loadCodificationTable()
    text = loadProgramText()
    ignorable = [" ", "\n"]
    pif = []
    bstIdentifiers = BST()
    bstConstants = BST()
    i = 0
    length = len(text)
    while i < length:
        word = ""
        while text[i] not in separators:
            word += text[i]
            i += 1
        if word in reserved:
            code = map[word]
            pif.append((code, -1))
        elif validIdentifier(word):
            position = bstIdentifiers.addElem(word)
            pif.append((1, position))
        elif validNumber(word):
            position = bstConstants.addElem(word)
            pif.append((2, position))
        else:
            raise Exception("Invalid token!")
        sep = ""
        while i < length and text[i] in separators:
            if text[i] == "'":
                if sep != '':
                    pif.append((map[sep], -1))
                    sep = ""
                assert (text[i + 2] == "'")
                position = bstConstants.addElem("'" + text[i + 1] + "'")
                pif.append((2, position))
                print('then branch', position, text[i + 1])
                i += 2
            else:
                if text[i] not in ignorable:
                    if possibleSeparator(sep + text[i], operands):
                        sep += text[i]
                    else:
                        if sep != '':
                            code = map[sep]
                            pif.append((code, -1))
                        sep = text[i]
            i += 1
        if sep in operands:
            pif.append((map[sep], -1))
    print('IDENTIFIERS:')
    printBST(bstIdentifiers.getRoot())
    print('CONSTANTS')
    printBST(bstConstants.getRoot())
    print('PIF')
    for x in pif:
        print(x[0])
    return pif, bstIdentifiers, bstConstants
Пример #3
0
    def test_deleteNodeRightChildren(self):
        arbol = BST()
        arbol.add(10)
        arbol.add(50)
        arbol.add(20)
        arbol.add(80)

        arbol.delete(50)
Пример #4
0
 def test_deleteRoot_onlyRight(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(50)
     arbol.delete(5)
Пример #5
0
 def test_deleteRoot_onlyLeft(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(1)
     arbol.delete(5)
Пример #6
0
 def test_onlyRoot(self):
     arbol = BST()
     arbol.add(5)
     arbol.delete(5)
Пример #7
0
 def test_findEmpty(self):
     BST().find(60)
Пример #8
0
from BinaryTree import BST

my_tree = BST.BinarySearchTree()

my_tree.display()

my_tree.insert(5, "five")
my_tree.insert(6, "six")
my_tree.insert(3, "three")
my_tree.insert(8, "eight")
my_tree.insert(2, "two")
my_tree.insert(9, "nine")
my_tree.insert(7, "seven")

my_tree.display()

print(my_tree.find(9))
Пример #9
0
 def test_insert(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
Пример #10
0
 def test_min(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     assert arbol.find_min() == 5
Пример #11
0
 def test_preorderEmpty(self):
     BST().preorder()
Пример #12
0
 def test_postorder(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.postorder()
Пример #13
0
 def test_insertRepeated(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(5)
Пример #14
0
 def test_inorderEmpty(self):
     BST().inorder()
Пример #15
0
 def test_minEmpty(self):
     arbol = BST()
     arbol.find_min()
Пример #16
0
    def test_deleteRoot_twoChildren(self):
        arbol = BST()
        arbol.add(10)
        arbol.add(50)
        arbol.add(20)
        arbol.add(7)
        arbol.add(8)
        arbol.add(5)
        arbol.add(1)

        arbol.delete(10)
Пример #17
0
 def test_deleteEmpty(self):
     BST().delete(5)
Пример #18
0
 def test_postorderEmpty(self):
     BST().postorder()
Пример #19
0
 def test_maxEmpty(self):
     arbol = BST()
     arbol.find_max()
Пример #20
0
 def test_deleteRootMoreNodes(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.delete(5)
Пример #21
0
 def test_find(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     assert arbol.find(8) == True
Пример #22
0
 def test_deleteNodeLeftChildren(self):
     arbol = BST()
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(5)
     arbol.add(1)
     arbol.delete(5)
Пример #23
0
 def test_findUnexist(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     assert arbol.find(666) == False
Пример #24
0
from BinaryTree.Material import User
from BinaryTree.BST import *

u1 = User(22, "April Mayo")
u2 = User(46, "Diego Diaz")
u3 = User(15, "Carlos Casas")
u4 = User(10, "Juan Muros")
u5 = User(25, "Miluzca Milan")
u6 = User(36, "Erick Tucto")

tree = BST()
tree.insert(u1)
tree.insert(u2)
tree.insert(u3)
tree.insert(u6)
print(tree.right.left.root.full_name)
Пример #25
0
 def test_delete(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.delete(5)