class Noeud: def __init__(self, v, c = []): self.v = v self.c = c def parcour_largeur(n): stack = [] stack.append(n) while len(stack) > 0: current = stack.pop(0) for s in current.c: stack.append(s) print(current.v) def parcour_largeur(n): stack = [] stack.append(n) while len(stack) > 0: current = stack.pop(0) for s in current.c: stack.append(s) print(current.v) def parcour_profondeur(n): stack = [] stack.append(n) while len(stack) > 0: current = stack.pop() for s in reversed(current.c): stack.append(s) print(current.v) def parcour_profondeur_rec(n): if len(n.c) > 0: parcour_profondeur_rec(n.c[0]) print(n.v) if len(n.c) > 1: parcour_profondeur_rec(n.c[1]) def parcour_profondeur_rec_dic(n, A): if len(A[n]) > 0: parcour_profondeur_rec_dic(A[n][0], A) print(n) if len(A[n]) > 1: parcour_profondeur_rec_dic(A[n][1], A) racine = Noeud("chien", [Noeud("petit", [Noeud("le")]), Noeud("et", [Noeud("jaune"), Noeud("noir")])]) parcour_profondeur_rec(racine) A = {"chien": ["petit", "et"], "petit": ["le"], "le": [], "et": ["jaune", "noir"], "jaune": [], "noir": [] } parcour_profondeur_rec_dic("chien", A) print(A.keys())