Exemplo 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
Exemplo n.º 2
0
    def __read_database(self, csv2_path):
        """Carrega a base de dados normalizada, cria as sub-àrvores e atualiza os atributos da classe."""
        with open((csv2_path), "r", encoding='UTF8') as csv2_file:
            data2 = csv.reader(csv2_file)
            next(data2)  # pula o header da planilha

            self.__tree['Doutorado'] = AVL_Tree()
            self.__tree['Mestrado'] = AVL_Tree()
            self.__tree['Especializacao'] = AVL_Tree()
            self.__tree['Graduacao'] = AVL_Tree()

            for row in data2:
                self.__insert(row)
                self.count['general'] = 0

        self.__update_size()
        self.__update_words()
        self.__merge_trees()

        print('\nDados carregados com sucesso')
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def __init__(self,
              interval,
              parent=None,
              leftChild=None,
              rightChild=None,
              height=None,
              bst=AVL_Tree(),
              root=None):
     self.interval = interval
     self.parent = parent
     self.leftChild = leftChild
     self.rightChild = rightChild
     self.height = height
     self.root = root
     self.bst = bst
Exemplo n.º 5
0
 def __init__(self):
     super().__init__()
     self.setupUi(self)
     self.pushButton.clicked.connect(self.sort)
     self.myTree=AVL_Tree()
     self.root=None
Exemplo n.º 6
0
            root = root.left


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)