-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.py
87 lines (77 loc) · 2.8 KB
/
Table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from Person import *
from PhoneBook import *
from Table import *
from Node import *
from BST import *
class Table:
def __init__(self, data):
self.data = data # Liste de Dictionnaires
# Un attribut de la table par case du Dictionnaire
def printTable(self):
for dico in self.data:
print(dico)
def addEntity(self):
dico = {}
self.data.append(dico)
if len(self.data) == 1: # Cas de création de la table
finished = 0
print("Let's start with the attributes in your table")
print("First attribute?")
a = str(input())
print("Value ?")
b = input()
dico[a] = b
print("Other attributes? 0 for yes, 1 for no")
finished = int(input())
while finished == 0:
print("Attribute ?")
a = str(input())
print("Value ?")
b = input()
dico[a] = b
print("Other attributes? 0 for yes, 1 for no")
finished = int(input())
else: # Cas où la liste dispose déjà d'au moins un dictionnaire
for key in self.data[0].keys():
print(str(key) + ": ")
dico[key] = input()
def buildAllBST(self):
allBST = [] # liste de tous les arbres
for att in self.data[0].keys(): # Pour chaque argument, on crée un arbre
a = BST()
for dico in self.data: # Pour chacun des Dictionnaires, on ajoute l'argument 'att' dans l'arbre
node = Node(dico[att], self.data.index(dico))
a.addNode(node)
allBST.append(a)
return allBST
def whichAtt(self): # Demande et renvoie l'index de l'attribut voulu
done = False
result = -1
while done == False:
print("What is the desired attribute ?\n")
i = 0
for att in self.data[0].keys():
print("For the " + str(att) + ", enter " + str(att))
i += 1
result = input()
for att in self.data[0].keys():
if result == att:
done = True
return result
def buildBST(self, att):
a = BST()
for dico in self.data:
node = Node(dico[att], self.data.index(dico))
a.addNode(node)
return a
def delBST(self, tree):
del(tree.head)
def rebuildBSTUser(self):
att = self.whichAtt()
tree = self.buildBST(att)
return tree
def reBuildBST(self, tree):
tree1 = self.buildBST(att)
def printAllTrees(self, allTrees): # allTrees est une liste des arbres (fournie par buildAllBST)
for arbre in myTableTrees:
print(arbre.affInfixe())