Esempio n. 1
0
def avl_file_reader(file):  # this function loads file in to avl tree

    avl_tree = AVL_Tree()  # stores avl tree in to a vairable

    for line in file:

        word = line.strip('\n').lower()
        avl_tree.insert(Node(word))

    file.close()

    return avl_tree
Esempio n. 2
0
class Win(QMainWindow,Ui_Frame):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton.clicked.connect(self.sort)
        self.myTree=AVL_Tree()
        self.root=None

    def sort(self):
        nums=self.getTextList()
        self.root=None
        for num in nums:
            self.root=self.myTree.insert(self.root,int(num))

        self.circles_point=[]
        self.font_point=[]
        self.line_point=[]
        self.setPoint(self.root,rootx,rooty,Rx,Ry)
        self.setFont(self.root,rootx,rooty,Rx,Ry)
        self.setLine(self.root,rootx,rooty,Rx,Ry)
        self.draw()

    def getTextList(self):
        nums=self.lineEdit.text().split(',')
        return nums

    def setPoint(self,root,x,y,rx,ry):
        if root:
            self.setPoint(root.left,x-rx,y+ry,rx/1.5,ry/1.5)
            self.circles_point.append([QPoint(x,y),Radix,Radix])
            self.setPoint(root.right,x+rx,y+ry,rx/1.5,ry/1.5)

    def setFont(self,root,x,y,rx,ry):
        if root:
            self.setFont(root.left,x-rx,y+ry,rx/1.5,ry/1.5)
            self.font_point.append([QRectF(x-Radix,y-Radix,2*Radix,2*Radix),str(root.val)])
            self.setFont(root.right,x+rx,y+ry,rx/1.5,ry/1.5)

    def setLine(self,root,x,y,rx,ry):
        if root:
            if root.left:
                self.line_point.append([x,y,x-rx,y+ry])
            if root.right:
                self.line_point.append([x,y,x+rx,y+ry])
            self.setLine(root.left,x-rx,y+ry,rx/1.5,ry/1.5)
            self.setLine(root.right,x+rx,y+ry,rx/1.5,ry/1.5)

    def draw(self):
        cir=draw_circle(self.circles_point,self.font_point,self.line_point)
        self.scrollArea.setWidget(cir)
Esempio n. 3
0
if __name__ == "__main__":
    results = {'AVL': [], 'RBT': []}
    result = {'AVL': 0, 'RBT': 0}
    results_search = {'AVL': [], 'RBT': []}
    result_search = {'AVL': 0, 'RBT': 0}

    for aux in range(NUM_REPETICOES):
        lista = cria_lista_sem_repeticao()

        for key in result.keys():
            if key == 'AVL':
                inicio = time()
                avlTree = AVL_Tree()
                root = None
                for i in lista:
                    root = avlTree.insert(root, i)

            elif key == 'RBT':
                inicio = time()
                rbt = Tree()
                for i in lista:
                    rb_insert(rbt, Node(i))

            fim = time()
            tempo = Decimal(fim - inicio)

            result[key] = tempo
            results[key].append(tempo)

        for key in result_search.keys():
            if key == 'AVL':