def main(): """Program to demonstrate trees of different types.""" # Let's make some trees of different classes (subclasses) tree_list = [ trees.Tree(), trees.EvenTree(), trees.UpsideDownTree(), trees.WideTree(), trees.QuickTree(), trees.FruitTree(), trees.PineTree() ] # display all the trees for tree in tree_list: print(tree.__class__) print(tree) print("Time to grow!") # grow them several times for _ in range(5): for tree in tree_list: tree.grow(5, 2) # display all the trees again for tree in tree_list: print(tree.__class__) print(tree)
def getHuffmanTree(self, f): """for tupla in f: print(tupla) input()""" if len(f) == 2: """Crear y regresar arbol""" left = Trees.Tree(None, None, f[0]) rigth = Trees.Tree(None, None, f[1]) return Trees.Tree(left, rigth) etiqueta = str(f[0][2]) + "+" + str(f[1][2]) fcopy = f.copy() del fcopy[0] del fcopy[0] fcopy.append((None, None, f[0][2] + f[1][2], [etiqueta])) fcopy.sort(key=lambda tupla: tupla[2]) t = self.getHuffmanTree(fcopy) left = Trees.Tree(None, None, f[0]) rigth = Trees.Tree(None, None, f[1]) self.insertarArbol(t, left, rigth, etiqueta) return t
def expression(self): me = Trees.Tree() if self.Tok.type == "ID": # aR' # semantic: check table for id me.addNextOperand(self.Tok) if self.Works[self.boi + 1].dataC != "(": symb = self.Table.getSymbol(self.Tok.dataC) else: symb = self.Table.getFuncSymbol(self.Tok.dataC) self.sDict[ "ID"] = self.Tok.dataC # capture ID #add to druple maybe # accept: ID self.accept(self.Tok.type, "ID") expr = self.expression_prime(me) last = self.createInstruct(me.root) return self.testExpression([symb, expr]), (last, me.root) elif self.Tok.type == "INTEGER" or self.Tok.type == "FLOAT": # bX'V'T' me.root = Trees.TreeNode(self.Tok) if self.Tok.type == "FLOAT": type = "float" else: type = "int" num = Symbol(type, "NUM", self.Tok.dataC) # accept: NUM self.accept(self.Tok.type, self.Tok.type) term = self.term_prime(me) adde = self.additive_expression_prime(me) sime = self.ok_expression_prime(me) last = self.createInstruct(me.root) return self.testExpression([num, term, adde, sime]), (last, me.root) elif self.Tok.dataC == "(": # accept: ( self.accept(self.Tok.dataC, "(") expr = self.expression() last = expr[1][1] expr = expr[0] if self.Tok.dataC == ")": # accept: ) self.accept(self.Tok.dataC, ")") term = self.term_prime(me) adde = self.additive_expression_prime(me) sime = self.ok_expression_prime(me) last = self.createInstruct(me.root) return self.testExpression([expr, term, adde, sime]), (last, me.root) print("REJECT") sys.exit(0)
# -*- coding: utf-8 -*- import Trees as Tr import Independence_Polys as IP T = Tr.Tree(10) T.print_rel() P = IP.IndeP(10) print(P.The_Polynom) # print(P.The_Tree.print_rel()) # P.The_Polynom.show_graph(-10, 10) # print(P.The_Polynom.roots())
def __init__(self, size: int) -> object: self.The_Tree = trs.Tree(size) self.The_Polynom = self.ComputePOL(self.The_Tree)