Académique Documents
Professionnel Documents
Culture Documents
Arbres
Arbres
Stéphane Grandcolas
stephane.grandcolas@univ-amu.fr
− +
/ t 75 z
y 2
(y/2 − t) × (75 + z)
le livre
Georges
Ginette
feuilles
....
a1 a2 ak
4
2
6
5 9
10
3
7 8
1
10
3
7 8
1
4
2
6
5 9
10
3
7 8
1
racine
feuilles
racine
niveaux
noeud de degré 3
chemin à la racine
ancetre
profondeur=2 hauteur=5
descendant frère
fils droit
fils gauche
nombre de noeuds
2
16
Arbre vide :
8 x
h+, h8, , i, h×, h+, h75, , i, h4, , ii, h61, , iii
+ 61
75 4
struct noeud
{
TYPE_VALEUR val;
ARBRE fg, fd;
};
12 a−>fg 12 a−>fg−>fd
1 7 1 7
91 67 82 91 67 82
14 11
14 11
ARBRE a;
a = CreerNoeud(x, p, NULL);
ParcoursPrefixe (a->fg); 91 67 82
ParcoursPrefixe (a->fd); 7
} 61
}
12 1 91 67 7 82 61
AfficherLaValeur(a->val); 91 67 82
ParcoursInfixe (a->fd); 6
} 61
}
91 1 67 12 7 61 82
1 2 5
91 67 82
4
61
91 67 1 61 82 7 12
valeurs inférieures à 34 p
34
22 66
7 29 50 71
17 25 32 37 56 70 81
9 21 23 28 30 36 44 55 68 80 97
8 16 27 35 52 67 69 94
26 51 88
Définition du type.
typedef struct noeud *ARBRE;
struct noeud
{
VALEUR val;
ARBRE fg, fd, pere;
};
L’accès au père est utile par exemple pour chercher le successeur d’un
noeud
7 8 9 16 17 21 22 23 25 26 27 28 29 30 32 34 35 36 37 ...
34
<34
22 66
>22
7 29 50 71
<29
17 25 32 37 56 70 81
>25
9 21 23 28 30 36 44 55 68 80 97
<28
8 16 27 35 52 67 69 94
26 51 88
22 66
8 29 50 71
17 25 32 35 56 70 81
9 21 23 28 30 34 44 55 69 80 97
8 16 27 34 52 67 69 94
26 51 88
22 66
8 29 50 71
17 25 32 35 56 70 81
9 21 23 28 30 34 44 55 69 80 97
8 16 27 31 34 52 67 69 94
26 51 88
22 66
7 29 50 71
17 25 32 37 56 70 81
9 21 23 28 30 36 44 55 68 80 97
8 16 27 31 35 52 67 69 94
26 51 88
22 66
7 29 50 71
17 25 32 37 56 70 81
9 21 23 28 30 36 44 55 68 80 97
8 16 27 31 35 52 67 69 94
26 51 88
22 66
7 29 50 71
17 25 32 37 56 70 81
9 21 23 28 30 36 44 55 68 80 97
8 16 27 31 35 52 69 94
26 51 88
22 66
8 29 50 71
17 25 32 35 56 70 81
9 21 23 28 30 34 44 55 68 80 97
8 16 27 31 34 52 69 94
26 51 88
22 66
8 29 50 71
17 25 32 35 56 70 81
9 21 23 28 30 34 44 55 69 80 97
8 16 27 31 34 52 94
26 51 88
22 66
8 29 50 71
17 25 32 35 56 70 81
9 21 23 28 30 34 44 55 69 80 97
8 16 27 31 34 52 94
26 51 88
22 66
8 29 50 71
17 25 32 35 56 70 81
9 21 23 28 30 34 44 55 69 80 97
8 16 27 31 34 52 94
26 51 88
22 56
8 29 50 71
17 25 32 35 55 70 81
9 21 23 28 30 34 44 52 69 80 97
8 16 27 31 34 51 94
26 88
racine
fils ainé
frères
.....
a1 a2 ak
struct noeud
{
TYPE_VALEUR val;
LISTE_DARBRES fils;
};
struct maillon
{
ARBREn le_fils;
LISTE_DARBRES suiv;
};
struct noeud
{
TYPE_VALEUR val;
ARBREn fa;
ARBREn fr;
};
A D
I R U E
R L T * X *
* * * *