mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-07 10:50:36 +00:00
Auto urgent commit.
This commit is contained in:
@@ -23,17 +23,41 @@ class Arbre_Binaire(object):
|
|||||||
profondeur_gauche = self.ss_arbre_gauche.hauteur() if self.ss_arbre_gauche else 0
|
profondeur_gauche = self.ss_arbre_gauche.hauteur() if self.ss_arbre_gauche else 0
|
||||||
profondeur_droite = self.ss_arbre_droit.hauteur() if self.ss_arbre_droit else 0
|
profondeur_droite = self.ss_arbre_droit.hauteur() if self.ss_arbre_droit else 0
|
||||||
return 1+max(profondeur_droite,profondeur_gauche)
|
return 1+max(profondeur_droite,profondeur_gauche)
|
||||||
def affichage(arbre):
|
|
||||||
pass
|
def parcours_largeur(self):
|
||||||
if arbre.est_vide():
|
if self.est_vide():
|
||||||
return ([])
|
return None
|
||||||
|
file = [(self, 0)]
|
||||||
|
niveaux = {}
|
||||||
|
while file:
|
||||||
|
noeud, niveau = file.pop(0)
|
||||||
|
if niveau not in niveaux:
|
||||||
|
niveaux[niveau] = []
|
||||||
|
niveaux[niveau].append(noeud.racine)
|
||||||
|
if noeud.ss_arbre_gauche:
|
||||||
|
file.append((noeud.ss_arbre_gauche, niveau + 1))
|
||||||
|
if noeud.ss_arbre_droit:
|
||||||
|
file.append((noeud.ss_arbre_droit, niveau + 1))
|
||||||
|
return niveaux
|
||||||
|
def affiche(arbre, traitement):
|
||||||
|
if arbre:
|
||||||
|
sag,racine,sad = arbre
|
||||||
|
if traitement == 'prefixe':
|
||||||
|
print(racine)
|
||||||
|
affiche(sag,"prefixe")
|
||||||
|
if traitement == "infixe":
|
||||||
|
print(racine)
|
||||||
|
affiche(sad,"infixe")
|
||||||
|
if traitement == "postfixe":
|
||||||
|
print(racine)
|
||||||
|
def list_to_btree(liste):
|
||||||
|
if not liste:
|
||||||
|
return Arbre_Binaire()
|
||||||
else:
|
else:
|
||||||
racine = arbre.racine
|
racine = Arbre_Binaire(racine=liste[0])
|
||||||
prefixe = arbre.ss_arbre_gauche
|
for elt in liste[1:]:
|
||||||
suffixe = arbre.ss_arbre_droit
|
racine.insertion(elt) # besoin de insertion
|
||||||
#todo
|
return racine
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
arbre = Arbre_Binaire(1, Arbre_Binaire(2), Arbre_Binaire(3))
|
arbre = Arbre_Binaire(1, Arbre_Binaire(2), Arbre_Binaire(3))
|
||||||
print("taille arbre :", arbre.taille())
|
print("taille arbre :", arbre.taille())
|
||||||
|
|||||||
Reference in New Issue
Block a user