-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArbre.java
92 lines (68 loc) · 1.53 KB
/
Arbre.java
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
88
89
90
91
92
/*
* Thibault ANIN
* TP3 E2
*/
public class Arbre {
private Liste entier;
private boolean vide;
private Arbre filsGauche;
private Arbre filsDroit;
public Arbre() {
vide = true;
}
public Arbre(Liste info, Arbre filsG, Arbre filsD) {
entier = info;
filsGauche = filsG;
filsDroit = filsD;
vide = false;
}
public boolean vide()
{
return vide;
}
public Liste info()
{
return entier;
}
public Arbre filsGauche()
{
return filsGauche;
}
public Arbre filsDroit()
{
return filsDroit;
}
public void afficheInfixe()
{
if(!filsGauche.vide())
filsGauche.afficheInfixe();
if(!entier.reste().vide())
System.out.println((char) entier.reste().tete() + ":" + entier.tete());
else
System.out.println(entier.tete());
if(!filsDroit.vide())
filsDroit.afficheInfixe();
}
public void affichePrefixe()
{
if(!entier.reste().vide())
System.out.println((char) entier.reste().tete() + ":" + entier.tete());
else
System.out.println(entier.tete());
if(!filsGauche.vide())
filsGauche.affichePrefixe();
if(!filsDroit.vide())
filsDroit.affichePrefixe();
}
public static boolean contenu(Arbre a, Liste l)
{
if(l.vide())
return true;
if(a.vide())
return false;
if(a.info().tete() == l.tete())
return contenu(a.filsGauche(),l.reste()) || contenu(a.filsDroit(),l.reste());
else
return contenu(a.filsGauche(),l) || contenu(a.filsDroit(),l);
}
}